-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.client.js
117 lines (114 loc) · 3.25 KB
/
webpack.client.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
const webpack = require('webpack');
// local
const path = require('path');
// plugins
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// setup the environment
require('dotenv').config();
// if dev mode
const DEV = process.env.NODE_ENV !== 'production';
// settings
const dist = DEV ? 'dev' : 'build';
const settings = {
entry: {
main: './client/app/app.js'
},
output: {
filename: '[name].[contenthash].js',
cssFilename: '[name].css',
cssChunkFilename: '[name].[contenthash].css',
client: dist,
html: './client/index.html'
}
};
module.exports = {
mode: DEV ? 'none' : 'production',
entry: path.join(__dirname, settings.entry.main),
devtool: DEV ? 'source-map' : '',
stats: 'errors-warnings',
output: {
filename: settings.output.filename,
path: path.join(__dirname, settings.output.client)
},
devServer: {
contentBase: path.join(__dirname, dist),
compress: true,
port: 8000
},
plugins: [
DEV ? () => {} : new OptimizeCSSAssetsPlugin({}),
new webpack.DefinePlugin({
ENV_ORIGIN: JSON.stringify(process.env.LAMBDA_SERVER || '')
}),
new HTMLWebpackPlugin({
template: path.join(__dirname, settings.output.html),
minify: {
removeAttributeQuotes: true,
removeComments: true,
collapseWhitespace: true,
html5: true
}
}),
new webpack.HashedModuleIdsPlugin(),
new MiniCssExtractPlugin({
filename: settings.output.cssFilename,
chunkFilename: settings.output.cssChunkFilename
}),
new CopyPlugin({
patterns: [{
from: 'client/assets',
to: 'assets'
}, {
from: 'client/manifest.json',
to: 'manifest.json'
}, {
from: 'LICENSE',
to: 'LICENSE.txt'
}, {
from: './node_modules/@digitalkaoz/preload-polyfill/dist/preload-polyfill.min.js',
to: 'vendors/preload-polyfill.min.js'
}, {
from: './node_modules/@digitalkaoz/preload-polyfill/dist/preload-polyfill-invoke.min.js',
to: 'vendors/preload-polyfill-invoke.min.js'
}, {
from: './node_modules/@digitalkaoz/preload-polyfill/dist/preload-polyfill-inline.min.js',
to: 'vendors/preload-polyfill-inline.min.js'
}, {
from: './node_modules/localforage/dist/localforage.min.js',
to: 'vendors/localforage.min.js'
}, {
from: './node_modules/ac-colors/dist/ac-colors.min.js',
to: 'vendors/ac-colors.min.js'
}]
})
],
resolve: {
alias: {
app: path.resolve(__dirname, 'client/app/')
},
extensions: ['.jsx', '.js']
},
module: {
// set the rules of transpiling
rules: [
{
// transpile es6 in all the .js or .jsx files
test: /[.js|.jsx]$/,
// don't transpile code in the node modules folder
exclude: /node_modules/,
use: {
loader: 'babel-loader?cacheDirectory=true'
}
}, {
test: /\.css$/,
use: [
{ loader: DEV ? 'style-loader' : MiniCssExtractPlugin.loader },
{ loader: 'css-loader' }
]
}
]
}
};