-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
85 lines (83 loc) · 2.03 KB
/
webpack.config.js
File metadata and controls
85 lines (83 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const mode =
process.env.NODE_ENV === 'production' ? 'production' : 'development';
const publicOutputPath = 'http://localhost:9002/wp/';
module.exports = {
mode,
// In production, always be IE11 compatible. In dev, be IE11 compatible
// if IE11=1 is in the environment, as this currently breaks hot reload:
// https://github.com/webpack/webpack-dev-server/issues/2758
target: process.env.IE11 ? 'es5' : mode === 'development' ? 'web' : 'es5',
entry: [
`./src/js/index.js`,
`./src/scss/index.scss`
],
output: {
...(mode === 'development'
? {
filename: 'site.js',
publicPath: publicOutputPath
}
: {
path: path.resolve(
__dirname,
`lib/modules/apostrophe-assets/public/js`
),
filename: 'site.js'
}),
chunkFormat: 'array-push'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
filename: mode === 'development' ? 'site.css' : '../css/site.css'
})
],
...(mode === 'development'
? {
devServer: {
hot: true,
inline: true,
host: '0.0.0.0',
headers: {
'Access-Control-Allow-Origin': '*'
},
publicPath: '/wp/',
port: 9002,
allowedHosts: ['.localhost'],
proxy: {
'/': 'http://localhost:3000'
}
}
}
: {}),
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
},
{
test: /\.scss$/,
use: [
// Instead of style-loader, to avoid a flash of
// unstyled content
MiniCssExtractPlugin.loader,
// Parses CSS imports
'css-loader',
// Parses SASS imports
'sass-loader'
]
}
]
}
};