forked from rheinardkorf/webpack-wordpress-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
93 lines (89 loc) · 2.19 KB
/
webpack.config.js
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
86
87
88
89
90
91
92
93
const path = require( 'path' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const StyleLintPlugin = require('stylelint-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const settings = {
// The BrowserSync hostname
host: 'localhost',
// The port to run BrowserSync's server on
port: 3333,
// A target to proxy all BrowserSync requests to.
// This can be a local web server, Vagrant or a docker container.
// This is your local/VM WordPress development site.
proxy: 'localhost',
// If you have your Site URL for WordPress set to anything else other than the proxy address,
// we need to override all URL. In this example I am overriding my site at http://training-ground.local
urlOverride: /training-ground\.local/g
};
module.exports = {
entry: './js/src/main.js',
output: {
filename: 'scripts.js',
path: path.resolve( __dirname, 'js' )
},
devtool: 'source-map',
module: {
loaders: [
// Setup ESLint loader for JS.
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true,
}
},
// Run JS through Babel Loader before bundling it to `scripts.js`
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
// Run Sass through loaders before bundling into `style.css`
{
test: /\.scss$/,
enforce: 'pre',
loader: ExtractTextPlugin.extract( [
{
loader: 'css-loader',
options: {
minimize: true,
sourceMap: true
}
},
{
loader: 'sass-loader'
}
] )
},
]
},
plugins: [
new ExtractTextPlugin( {
filename: '../css/style.css'
} ),
new StyleLintPlugin({ syntax: 'scss' }),
new UglifyJSPlugin({
mangle: {
// Skip mangling these
except: ['$super', '$', 'exports', 'require']
},
sourceMap: true
}),
new BrowserSyncPlugin({
host: settings.host,
port: settings.port,
proxy: settings.proxy,
rewriteRules: [
{
match: settings.urlOverride,
fn: function (req, res, match) {
return settings.host + ':' + settings.port;
}
}
]
})
]
}