-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (107 loc) · 3.03 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
const path = require('path');
const merge = require('webpack-merge');
const parts = require('./webpack.parts');
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const { ReactLoadablePlugin } = require('react-loadable/webpack');
const PATHS = {
app: path.join(__dirname, 'app'),
client: path.join(__dirname, 'client'),
server: path.join(__dirname, 'server'),
build: path.join(__dirname, 'server', 'public'),
};
const commonConfig = merge([
{
entry: {
client: PATHS.client,
},
output: {
path: PATHS.build,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: '/',
},
resolve: {
alias: {
images: path.resolve(__dirname, 'assets/img/'),
app: path.resolve(__dirname, 'app/'),
theme: path.resolve(__dirname, 'app/theme'),
utils: path.resolve(__dirname, 'app/utils/'),
pages: path.resolve(__dirname, 'app/pages/'),
config: path.resolve(__dirname, 'app/config'),
actions: path.resolve(__dirname, 'app/actions/'),
reducers: path.resolve(__dirname, 'app/reducers/'),
components: path.resolve(__dirname, 'app/components/'),
},
extensions: ['.js', '.jsx'],
},
node: {
fs: 'empty',
},
plugins: [
new ReactLoadablePlugin({
filename: `${PATHS.build}/react-loadable.json`,
}),
new Dotenv({
path: './.env', // Path to .env file (this is the default)
safe: true, // load .env.example (defaults to "false" which does not use dotenv-safe)
}),
],
},
parts.split(),
parts.cleanBuildPath({ include: PATHS.build }),
parts.loadJavaScript({ include: [PATHS.client, PATHS.app] }),
parts.loadImages({
options: {
limit: 15000,
name: '[name].[hash:8].[ext]',
},
}),
parts.assets({
path: PATHS.build,
}),
parts.happyPackThread('js', ['babel-loader']),
parts.happyPackThread('jsx', ['babel-loader']),
parts.extractCss(),
]);
const productionConfig = merge([
parts.setMode('production'),
{
output: {
path: PATHS.build,
chunkFilename: '[name].[chunkhash:8].bundle.js',
filename: '[name].[chunkhash:8].bundle.js',
publicPath: '/',
},
performance: {
hints: 'warning', // 'error' or false are valid too
maxEntrypointSize: 100000, // in bytes
maxAssetSize: 450000, // in bytes
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
],
},
parts.generateSourceMaps({ type: 'source-map' }),
parts.uglifyJs(),
parts.visualizer(),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production',
),
parts.attachRevision(),
]);
const developmentConfig = merge([
parts.setMode('development'),
parts.devServer({
host: 'localhost',
port: process.env.PORT,
}),
parts.generateSourceMaps({ type: 'cheap-module-eval-source-map' }),
]);
module.exports = (env) => {
console.log(env, 'this is env');
return env === 'production'
? merge(commonConfig, productionConfig)
: merge(commonConfig, developmentConfig);
};