-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (100 loc) · 2.57 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
const path = require('path')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const zopfli = require('@gfx/zopfli')
const BrotliPlugin = require('brotli-webpack-plugin')
function getBrandingRootPath () {
let rootPath = process.env.BRANDING_ROOT_PATH || 'branding-default'
if (!path.isAbsolute(rootPath)) {
rootPath = path.join(__dirname, rootPath)
}
return rootPath
}
function getBrandingScriptPath () {
return path.join(getBrandingRootPath(), 'js')
}
module.exports = (env, argv) => {
const plugins = [
new CleanWebpackPlugin()
]
if (argv.mode === 'production') {
plugins.push(new CompressionPlugin({
compressionOptions: {
numiterations: 15
},
algorithm(input, compressionOptions, callback) {
return zopfli.gzip(input, compressionOptions, callback)
}
}))
plugins.push(new BrotliPlugin({
asset: '[path].br[query]',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
}))
} else if (argv.mode === 'development') {
plugins.push(new webpack.HotModuleReplacementPlugin())
}
return {
entry: './src/index.js',
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: { presets: ["@babel/env"] }
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx'],
alias: {
Branding: getBrandingScriptPath()
}
},
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.join(__dirname, 'public/'),
port: 3000,
publicPath: 'http://localhost:3000/dist/',
hotOnly: true,
historyApiFallback: true
},
plugins: plugins
}
}