forked from ExpediaDotCom/haystack-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
123 lines (112 loc) · 4.01 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const path = require('path');
const webpack = require('webpack');
const Assets = require('assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// paths --------------------------------------------------------------------------------------------------------
const appPaths = {
public: path.join(__dirname, 'public/'),
bundles: path.join(__dirname, 'public/bundles'),
source: path.join(__dirname, 'src'),
sourceAppJsx: path.join(__dirname, 'src/app.jsx'),
sourceStyle: path.join(__dirname, 'src/'),
views: path.join(__dirname, 'views'),
indexView: path.join(__dirname, 'views/index.pug')
};
// progress plugin -------------------------------------------------------------------------------------------------
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const chalk = require('chalk'); // Provided through ProgressBarPlugin
const progressBarOptions = {
format: ` ${chalk.blue.bold('build')} [:bar] ${chalk.green.bold(':percent')} (:elapsed s) :msg`,
clear: false,
complete: chalk.yellow(' \u2708'),
incomplete: ' ',
width: 20
};
// environment specific configs -------------------------------------------------------------------------------------
let devtool = 'source-map';
let jsBundleFilename = 'bundles/js/[name].[chunkhash].js';
let cssBundleFilename = 'bundles/style/[name].[chunkhash].css';
if (process.env.NODE_ENV === 'development') {
devtool = 'eval-cheap-module-source-map';
jsBundleFilename = 'bundles/js/[name].js';
cssBundleFilename = 'bundles/style/[name].css';
}
// main config export -----------------------------------------------------------------------------------------------
module.exports = {
entry: {
app: appPaths.sourceAppJsx
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
babelrc: false,
plugins: ['lodash', 'transform-decorators-legacy'],
presets: ['env', 'react', 'stage-1']
}
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false
}
},
'less-loader'
]
},
{
test: /\.svg$/,
loader: 'svg-url-loader?encoding=base64'
}
]
},
plugins: [
new MiniCssExtractPlugin({filename: cssBundleFilename}),
new LodashModuleReplacementPlugin({
shorthands: true,
collections: true
}),
new ProgressBarPlugin(Object.assign({}, progressBarOptions)),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
generateStatsFile: false,
reportFilename: 'bundles/report.html',
openAnalyzer: false
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new Assets({filename: 'public/assets.json'})
],
output: {
path: appPaths.public,
publicPath: '/',
filename: jsBundleFilename,
sourceMapFilename: `${jsBundleFilename}.map`,
chunkFilename: jsBundleFilename
},
resolve: {
extensions: ['.json', '.js', '.jsx']
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
chunks: 'initial',
test: path.resolve(__dirname, 'node_modules'),
name: 'commons',
enforce: true
}
}
}
},
devtool
};