forked from webpackmonitor/webpackmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
103 lines (95 loc) · 2.4 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
94
95
96
97
98
99
100
101
102
103
const path = require('path');
const merge = require('webpack-merge');
const glob = require('glob');
const utils = require('./webpack.utils.js');
const webpack = require('webpack');
const WebpackMonitor = require('./plugin/npm-module/monitor');
const PATHS = {
app: path.join(__dirname, 'client/index.jsx'),
build: path.join(__dirname, 'build'),
};
module.exports = (env) => {
const common = merge([
{
entry: {
app: PATHS.app,
},
resolve: {
extensions: ['.js', 'json', '.jsx'],
},
devServer: {
historyApiFallback: true,
contentBase: './build',
},
module: {
rules: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react'],
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
],
},
],
loaders: [
{
test: /\.json$/,
loader: 'json-loader',
},
],
},
},
utils.purifyCSS({
paths: glob.sync(`${PATHS.app}/**/*.js`, { nodir: true }),
}),
]);
const development = {
output: {
path: PATHS.build,
filename: '[name].js',
},
plugins: [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('development') }),
],
};
const launch = merge([
{
output: {
path: path.join(__dirname, 'plugin/npm-module/build'),
filename: 'app.js',
},
plugins: [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
new WebpackMonitor({ launch: true, capture: false }),
],
},
utils.uglifyJS(),
]);
const confirm = merge([
{
output: {
path: path.join(__dirname, 'plugin/npm-module/build'),
filename: 'app.js',
},
plugins: [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('data') }),
new WebpackMonitor({ capture: true }),
],
},
]);
if (env === 'development') return merge([common, development]);
if (env === 'confirm') return merge([common, confirm]);
if (env === 'launch') return merge([common, launch]);
return common;
};