Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
87 lines (85 loc) · 2.97 KB
/
Copy pathwebpack.config.js
File metadata and controls
87 lines (85 loc) · 2.97 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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { EnvironmentPlugin } = require('webpack')
module.exports = (env, argv) => {
process.env.NODE_ENV = argv.mode
const isDev = argv.mode === 'development'
const srcPath = (subdir) => path.join(__dirname, 'src', subdir)
return {
entry: srcPath('index.tsx'),
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'dist'),
chunkFilename: 'bundle.[id].js',
},
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
components: srcPath('components'),
configs: srcPath('configs'),
contexts: srcPath('contexts'),
helpers: srcPath('helpers'),
screens: srcPath('screens'),
storage: srcPath('storage'),
interfaces: srcPath('interfaces'),
routes: srcPath('routes'),
},
},
module: {
rules: [
{
test: /\.worker\.ts$/,
use: {
loader: 'worker-loader',
options: {
filename: 'workers/[name].js',
chunkFilename: 'workers/[id].js',
},
},
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
exclude: /node_modules/,
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDev,
},
},
'css-loader',
'sass-loader',
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: isDev ? '[name].css' : '[name].[hash].css',
chunkFilename: isDev ? '[id].css' : '[id].[hash].css',
}),
new EnvironmentPlugin(['NODE_ENV']),
new HtmlWebpackPlugin({
template: srcPath('index.ejs.html'),
}),
new CopyPlugin({
patterns: [{ from: 'res/app-icon/48x48.ico', to: 'favicon.ico' }],
}),
],
optimization: {
splitChunks: {
chunks: 'all',
},
},
}
}