-
Notifications
You must be signed in to change notification settings - Fork 42
/
webpack.config.js
134 lines (132 loc) · 4.08 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
126
127
128
129
130
131
132
133
134
import autoprefixer from 'autoprefixer';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ESLintPlugin from 'eslint-webpack-plugin';
import HtmlWebPackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { createRequire } from 'module';
import path from 'path';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default (env, argv) => {
const devPlugins = argv.mode === 'production' ? [] : [new ESLintPlugin()];
return {
devtool: 'source-map',
node: {
global: true
},
entry: './src/js/main.js',
module: {
rules: [
{
test: /\.m?[jt]sx?$/,
exclude: [/node_modules/, /\.test\./, /__snapshots__/],
resolve: { fullySpecified: false },
loader: 'esbuild-loader',
options: {
loader: 'tsx',
jsx: 'automatic'
}
},
{
test: /\.(less|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
url: true
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: { plugins: [autoprefixer({})] },
sourceMap: true
}
},
{
loader: 'esbuild-loader',
options: {
loader: 'css',
minify: true
}
},
'less-loader'
]
},
{
test: /\.(png|jpe?g|gif|eot|ttf|woff|woff2)$/i,
exclude: [/node_modules/, /\.test\./, /__snapshots__/],
type: 'asset'
},
{
test: /\.svg$/i,
exclude: [/node_modules/, /\.test\./, /__snapshots__/],
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack']
}
]
},
optimization: {
minimize: argv.mode === 'production'
},
output: {
filename: '[name].min.js',
hashFunction: 'xxhash64',
path: path.resolve(__dirname, 'dist'),
publicPath: '/ui/'
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**/*', '!env.js'],
cleanAfterEveryBuildPatterns: ['!assets/fonts/*', '!assets/img/*']
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'node_modules/monaco-editor/min/vs/', to: 'vs' },
argv.mode !== 'production' && { from: 'node_modules/monaco-editor/min-maps/vs/', to: 'min-maps/vs' }
].filter(Boolean)
}),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
}),
new webpack.DefinePlugin({
ENV: JSON.stringify(argv.mode),
XTERM_VERSION: JSON.stringify(require('./package.json').dependencies['@xterm/xterm']),
XTERM_FIT_VERSION: JSON.stringify(require('./package.json').dependencies['@xterm/addon-fit']),
XTERM_SEARCH_VERSION: JSON.stringify(require('./package.json').dependencies['@xterm/addon-search'])
}),
new HtmlWebPackPlugin({
favicon: './src/favicon.svg',
hash: true,
template: './src/index.html'
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
...devPlugins
],
resolve: {
alias: {
'@babel/runtime/helpers/esm': path.resolve(__dirname, 'node_modules/@babel/runtime/helpers/esm')
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
fallback: {
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
crypto: 'crypto-browserify',
stream: require.resolve('stream-browserify'),
util: require.resolve('util/'),
'process/browser': require.resolve('process/browser')
}
},
target: 'web'
};
};