forked from okotoki/advanced-svg-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
88 lines (85 loc) · 2.25 KB
/
webpack.config.ts
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
import * as Dotenv from 'dotenv-webpack'
import * as HtmlWebpackInlineSourcePlugin from 'html-webpack-inline-source-plugin'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
import * as path from 'path'
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
import { TypedCssModulesPlugin } from 'typed-css-modules-webpack-plugin'
import * as webpack from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
const createConfig = (
env: any,
argv: webpack.Configuration
): webpack.Configuration => {
const isProd = argv.mode === 'production'
return {
mode: argv.mode,
devtool: false,
stats: 'minimal',
node: {
fs: 'empty'
},
entry: {
ui: './src/ui/index.tsx', // The entry point for your UI code
main: './src/main/index.ts'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.worker\.ts$/,
loader: [
{
loader: 'worker-loader',
options: { inline: true }
}
]
},
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
{
test: /\.css$/,
loader: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: true
}
}
]
},
{
test: /\.(png|jpg|gif|webp|svg)$/,
loader: [{ loader: 'url-loader' }]
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.css'],
plugins: [new TsconfigPathsPlugin()]
},
plugins: [
isProd ? new BundleAnalyzerPlugin() : () => {},
// new webpack.EnvironmentPlugin(["NODE_ENV", "API_ROOT", "API_KEY"]),
new webpack.EnvironmentPlugin({
DEBUG: !isProd
}),
new Dotenv(),
new TypedCssModulesPlugin({
globPattern: 'src/**/*.css'
}),
new HtmlWebpackPlugin({
template: './src/ui/index.html',
filename: 'ui.html',
inlineSource: '.(js)$',
chunks: ['ui']
}),
new HtmlWebpackInlineSourcePlugin()
]
}
}
export default createConfig