forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
91 lines (82 loc) · 2.15 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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const Visualizer = require('webpack-visualizer-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const distFolder = path.resolve(__dirname, 'dist')
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
const productionPlugins = [
new webpack.optimize.SplitChunksPlugin(
{
splitChunks: {
cacheGroups: {
commons: {
name: "commons",
chunks: "initial",
minChunks: 2
}
}
}
}),
new UglifyJsPlugin()
]
const devPlugins = []
const envPlugins = IS_PRODUCTION ? productionPlugins : devPlugins
// if (IS_PRODUCTION) {
// console.log('************* PRODUCTION BUILD ***************')
// }
module.exports = {
mode: IS_PRODUCTION ? 'production' : 'development',
node: false,
entry: './src/index.js',
output: {
path: distFolder,
filename: '[name].bundle.js',
chunkFilename: 'app-[name].bundle.js'
},
resolve: {
alias: {
'slim-js/Decorators$': path.resolve(
__dirname,
'./node_modules/slim-js/Decorators.js'
),
'slim-js': path.resolve(__dirname, './node_modules/slim-js/src/Slim.js'),
},
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
],
},
devtool: IS_PRODUCTION ? false : 'source-map',
target: 'web',
stats: 'errors-only',
devServer: {
contentBase: './dist',
},
plugins: [
new CleanWebpackPlugin(['dist']),
new CopyWebpackPlugin([
{
from: 'src/assets',
to: distFolder + '/assets',
},
{
from: 'src/favicon.ico',
to: distFolder,
},
]),
new HtmlWebpackPlugin({
template: './src/index.html',
title: 'Development',
}),
...envPlugins
],
}