-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
80 lines (71 loc) · 1.77 KB
/
webpack.config.babel.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
import webpack from 'webpack';
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const LAUNCH_COMMAND = process.env.npm_lifecycle_event;
const isProduction = LAUNCH_COMMAND === 'build';
process.env.BABEL_ENV = LAUNCH_COMMAND;
const STATIC_URL = isProduction ? '/app/' : '/';
const PATHS = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist')
};
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: path.join(__dirname, '/src/index.html'),
filename: 'index.html',
inject: 'body'
});
const productionPlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
});
const base = {
entry: './src/index.js',
output: {
filename: 'express-web-builder-bundle.js',
path: PATHS.dist,
publicPath: STATIC_URL
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
}
]
},
// the url-loader uses DataUrls.
{
test: /\.(ttf|eot|svg|woff|woff2|png|jpg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader'
}
]
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js']
}
};
const developmentConfig = {
devtool: 'cheap-module-inline-source-map',
devServer: {
allowedHosts: ['localhost'],
contentBase: PATHS.dist,
hot: true,
inline: true,
historyApiFallback: true
},
plugins: [HtmlWebpackPluginConfig, new webpack.HotModuleReplacementPlugin()]
};
const productionConfig = {
devtool: 'source-map',
plugins: [HtmlWebpackPluginConfig, productionPlugin]
};
export default Object.assign(
{},
base,
isProduction ? productionConfig : developmentConfig
);