-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.editor.config.js
More file actions
187 lines (184 loc) · 4.94 KB
/
webpack.editor.config.js
File metadata and controls
187 lines (184 loc) · 4.94 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const MiniCssExtractorPlugin = require('mini-css-extract-plugin');
const ESLintWebpackPlugin = require('eslint-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { DefinePlugin } = require('webpack');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const path = require('path');
const packageJson = require('./package.json');
const babelConfig = require('./babel-config.editor.js');
const jsConfig = require('./jsconfig.json');
const rootPath = path.resolve(__dirname, 'module', 'editor');
const sourcePath = path.resolve(rootPath, 'src');
const buildPath = path.resolve(__dirname, 'build');
const publicPath = path.resolve(rootPath, 'public');
const buildMode = process.env.NODE_ENV || 'production';
const isDev = buildMode === 'development';
const styleLoader = isDev ? require.resolve('style-loader') : MiniCssExtractorPlugin.loader;
const getResolveAliasFromJsConfig = () => {
return Object.entries(jsConfig.compilerOptions.paths).reduce((acc, [key, value]) => {
const transformedKey = key.replace('/*', '');
const paths = path.resolve(__dirname, value[0].replace('/*', ''));
return { ...acc, [transformedKey]: paths };
}, {});
};
module.exports = {
entry: path.resolve(sourcePath, 'index.jsx'),
output: {
path: path.resolve(buildPath),
filename: `js/[name].bundle.js`,
chunkFilename: `js/[name].bundle.chunk.js`,
assetModuleFilename: `media/[name].[hash][ext]`,
},
mode: buildMode,
devtool: isDev ? 'source-map' : undefined,
target: 'browserslist',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: require.resolve('babel-loader'),
options: { ...babelConfig },
},
},
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: [styleLoader, require.resolve('css-loader')],
},
{
test: /\.module\.css$/,
use: [
styleLoader,
{
loader: require.resolve('css-loader'),
options: {
modules: {
localIdentName: 'am-[local]-[hash:base64:5]',
localIdentContext: path.resolve(sourcePath),
exportLocalsConvention: 'camelCase',
},
},
},
],
},
{
test: /\.(jpg|jpeg|png|gif|mp3|svg)$/,
use: [require.resolve('file-loader')],
},
],
},
plugins: [
new ESLintWebpackPlugin({
extensions: ['.js', '.jsx'],
emitWarning: false,
cache: false,
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(publicPath, 'index.html'),
inject: true,
}),
new MiniCssExtractorPlugin({
filename: `css/editor.[contenthash:8].css`,
chunkFilename: `css/editor.[contenthash:8].chunk.css`,
}),
// new StylelintPlugin(),
new CopyPlugin({
patterns: [
{
from: 'module/editor/public/font',
to: 'font',
},
{
from: 'module/editor/public/css',
to: 'css',
},
],
}),
new DefinePlugin({
editor: {
VERSION: `'v${packageJson.version}'`,
},
grammar: {
VERSION: `'v${packageJson.grammarVersion}'`,
},
}),
],
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
optimization: {
minimize: !isDev,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 2020,
},
compress: {
ecma: 5,
comparisons: true,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
}),
new CssMinimizerPlugin(),
new CompressionPlugin(),
],
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
maxSize: 200000,
cacheGroups: {
react: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'react',
priority: -10,
enforce: true,
reuseExistingChunk: true,
},
common: {
test: /[\\/]node_modules[\\/]/,
name: 'commons',
priority: -40,
enforce: true,
reuseExistingChunk: true,
},
},
},
},
resolve: {
alias: getResolveAliasFromJsConfig(),
extensions: ['.js', '.jsx', '.css'],
fallback: {
'reflect-metadata': false,
},
},
stats: {
warnings: true,
},
devServer: {
static: [path.resolve(buildPath), path.resolve(publicPath)],
compress: false,
port: 4000,
liveReload: true,
hot: true,
},
};