-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
100 lines (94 loc) · 2.67 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
const path = require('path');
const webpack = require('webpack');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const colors = require('colors');
const env = process.env.ENV || 'dev',
port = process.env.PORT || 3000,
isProduction = env === 'production',
publicPath = '/',
htmlOptions = { isProduction, publicPath, useVendorChunks: false },
optionalPlugins = [],
polyfills = ['babel-polyfill'],
entry = ['./index.web.js'],
hot = [
'react-hot-loader/patch',
`webpack-dev-server/client?${publicPath}`,
'webpack/hot/only-dev-server',
];
if (!isProduction) {
optionalPlugins.push(new webpack.HotModuleReplacementPlugin());
optionalPlugins.push(new webpack.NamedModulesPlugin());
optionalPlugins.push(new webpack.NoEmitOnErrorsPlugin());
if (require('fs').existsSync('./web/vendor-manifest.json')) {
htmlOptions.useVendorChunks = true;
optionalPlugins.push(new webpack.DllReferencePlugin({
context: '.', manifest: require('./web/vendor-manifest.json'),
}));
}
if (!htmlOptions.useVendorChunks) {
console.log('(serving without '.grey + 'common-library-cache'.green +
', run '.grey + 'yarn vendor'.magenta + ' once to boost up build speed)'.grey);
}
optionalPlugins.push(new ProgressBarPlugin({
width: 39, complete: '▓'.green.bgGreen, incomplete: ' '.green.bgWhite,
format: 'Build (:bar) (:elapsed seconds)',
summary: false, customSummary: (buildTime) => {
console.log('Build completed after', ` ${buildTime} `.bgGreen);
},
}));
}
module.exports = {
cache: true,
devtool: isProduction ? false : 'eval-source-map',
entry: {
app: isProduction ? [...polyfills, ...entry] : [...polyfills, ...hot, ...entry]
},
output: {
publicPath, path: path.join(__dirname, 'web'),
filename: '[name].bundle-[hash].js',
chunkFilename: '[name].js',
},
resolve: {
alias: {
'react-native': 'react-native-web',
},
modules: ['node_modules'],
extensions: ['.js']
},
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
plugins: ['react-hot-loader/babel', ]
}
},
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{
test: /\.(png|jpg|svg|ttf)$/,
loader: 'file-loader?name=[name].[ext]'
},
{
test: /\.json/,
loader: 'json-loader'
}
],
},
plugins: [
new DefinePlugin({
ENV: JSON.stringify(env),
'process.env.NODE_ENV': JSON.stringify(env),
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new HtmlWebpackPlugin({
...htmlOptions,
template: 'index.ejs',
filename: 'index.html',
}),
...optionalPlugins,
]
};