-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
125 lines (123 loc) · 3.29 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
124
125
require('dotenv').config({ override: true })
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin')
const path = require('path')
const TerserJSPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')
module.exports = {
context: path.join(__dirname),
devServer: {
static: {
directory: path.join(__dirname, 'public'),
serveIndex: true
},
historyApiFallback: true,
hot: true,
port: process.env.PORT
},
entry: {
lib: './src/index.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}],
exclude: '/node_modules/'
},
{
test: /\.(?<ext>ico|png|svg|jpg|jpeg|gif|mp4|ogg|webm|woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]'
}
}
],
exclude: '/node_modules/'
}
]
},
optimization: {
minimizer: [
new TerserJSPlugin({
terserOptions: {
keep_fnames: true,
safari10: true
}
})
],
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
imask: {
chunks: 'all',
enforce: true,
name: 'imask',
test: /[\\/]node_modules[\\/]imask[\\/]/
}
},
name: 'common'
}
},
output: {
clean: true,
chunkFilename: '[name].[contenthash].js',
filename: '[name].[contenthash].js',
library: 'UI',
libraryTarget: 'umd',
path: path.resolve(__dirname, 'public'),
publicPath: process.env.PUBLIC_PATH
},
performance: {
hints: process.env.HINTS,
maxAssetSize: Number(process.env.MAX_ASSET_SIZE),
maxEntrypointSize: Number(process.env.MAX_ENTRYPOINT_SIZE)
},
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env)
}),
new webpack.EnvironmentPlugin({
SW_CACHE: Math.random().toString(32)
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, 'assets'), to: '.' }
]
}),
new HtmlWebpackPlugin({
inject: 'body',
template: 'index.html'
}),
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/(app|common|runtime)/]),
new BundleAnalyzerPlugin({
analyzerMode: process.env.ANALYZER_MODE
}),
new BundleStatsWebpackPlugin({
baselineFilepath: './../baseline.json'
})
],
resolve: {
alias: {
'@artifact': path.resolve(__dirname, 'prelude/artifact/'),
'@directive': path.resolve(__dirname, 'prelude/directive/'),
'@elements': path.resolve(__dirname, 'prelude/elements/'),
'@pixel': path.resolve(__dirname, 'prelude/pixel/'),
'@polyfill': path.resolve(__dirname, 'prelude/polyfill/'),
'@standard': path.resolve(__dirname, 'prelude/standard/')
},
extensions: ['.js', '.jsx']
}
}