-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
85 lines (77 loc) · 1.84 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
'use strict';
const path = require('path');
const glob = require('glob');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const env = process.env.ENV;
const isProduction = env === 'production';
// Find all jsx pages at the root of the js src structure.
const baseEntry = [];
const entries = {};
glob.sync('./src/js/*.{jsx,js}').forEach((page) => {
const entryName = path.basename(page, path.extname(page));
const fileName = `./${path.basename(page)}`;
entries[entryName] = baseEntry.concat([fileName]);
});
const babelRule = {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'env',
{
targets: {
browsers: ['last 2 versions'],
},
modules: false,
},
],
],
},
},
};
const outputPath = path.resolve(__dirname, 'public/js');
const webpackConfig = {
devtool: 'source-map',
context: path.resolve(__dirname, 'src/js'),
entry: entries,
resolve: {
extensions: ['.js', '.json', '.jsx']
},
output: {
filename: '[name].js',
path: outputPath,
publicPath: '/js/'
},
module: {
rules: [
babelRule,
{
test: /\.json$/,
loader: 'json-loader',
}
]
},
plugins: [
new CleanWebpackPlugin([outputPath]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery'
}),
// To extract node_modules imports into a vendor.js file.
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module => module.context && module.context.includes('node_modules'),
})
]
};
if (isProduction) {
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}));
}
module.exports = webpackConfig;