-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
84 lines (78 loc) · 1.95 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
require('dotenv/config')
const webpack = require('webpack')
const path = require('path')
const PurgecssPlugin = require('purgecss-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const glob = require('glob')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = (_, argv) => {
const isProd = !!argv.production
const createConfig = (projectName) => {
const config = {
devtool: isProd ? false : 'source-map',
mode: 'none',
entry: {
[projectName]: path.resolve(__dirname, 'client/src/index.tsx')
},
output: {
path: path.resolve(__dirname, 'dist/client'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{ loader: 'css-loader' }
]
},
{
test: /\.ts$|tsx/,
use: ['babel-loader'],
exclude: [/node_modules/]
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
plugins: [
new PurgecssPlugin({
paths: glob.sync(`../dist/${projectName}/*`)
}),
new HtmlWebpackPlugin({
filename: 'index.html',
hash: true,
template: path.resolve(__dirname, 'client/src/template.html'),
minify: isProd
? {
collapseWhitespace: true,
removeComments: true
}
: false
}),
// The presence of these env variables are checked at runtime when starting up the server
new webpack.DefinePlugin({
__AWS_DEFAULT_REGION__: JSON.stringify(process.env.AWS_DEFAULT_REGION),
__S3_BUCKET_NAME__: JSON.stringify(process.env.S3_BUCKET_NAME),
__SPRITE_SHEET_FILENAME_WITHOUT_EXT__: JSON.stringify(process.env.SPRITE_SHEET_FILENAME_WITHOUT_EXT)
})
],
watch: !isProd
}
if (isProd) {
config.mode = 'production'
config.optimization = {
minimizer: [new TerserPlugin()],
}
}
return config
}
const outputConfigs = [
createConfig('svg-cms')
]
return outputConfigs
}