forked from analogwp/analogwp-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
57 lines (52 loc) · 1.14 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
/**
* External Dependencies
*/
const webpack = require( 'webpack' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
// Enviornment Flag
const inProduction = 'production' === process.env.NODE_ENV;
// Externals
const externals = {
react: 'React',
moment: 'moment',
'react-dom': 'ReactDOM',
'@wordpress/i18n': { this: [ 'wp', 'i18n' ] },
};
// Webpack config
const config = {
entry: './client/index.js',
externals,
output: {
filename: 'assets/js/app.js',
path: __dirname,
library: [ 'ang', '[name]' ],
libraryTarget: 'this',
},
resolve: {
modules: [ __dirname, 'node_modules' ],
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
],
},
plugins: [
new CleanWebpackPlugin( {
cleanOnceBeforeBuildPatterns: [ 'build' ],
} ),
],
stats: {
children: false,
},
devtool: ! inProduction ? 'source-map' : '(none)',
};
// For Productions
if ( inProduction ) {
config.plugins.push( new webpack.optimize.UglifyJsPlugin( { sourceMap: true, mangle: false } ) );
config.plugins.push( new webpack.LoaderOptionsPlugin( { minimize: true } ) );
}
module.exports = config;