-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack.base.config.js
More file actions
153 lines (129 loc) · 4.64 KB
/
webpack.base.config.js
File metadata and controls
153 lines (129 loc) · 4.64 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
const webpack = require('webpack');
// const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require("path");
const mode = process.env.MODE;
if (!mode) {
throw new Error(`MODE environment variable is not set.`);
}
if (mode !== "development" && mode !== "production") {
throw new Error(`MODE environment variable is set to an invalid value: ${mode}, expected "development" or "production".`);
}
console.log(`Mode: ${mode}`);
module.exports = function (env) {
const outputDir = path.resolve(process.cwd(), "dist");
console.log(`Output: ${outputDir}`);
const targets = {
electron: "electron-renderer",
default: "web",
};
const defaultEnv = {
};
const processEnv = Object.assign(defaultEnv, process.env);
const devtools = {
development: "inline-source-map",
production: false,
};
return {
entry: {
'index': `./src/index.tsx`,
'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js',
'json.worker': 'monaco-editor/esm/vs/language/json/json.worker',
'css.worker': 'monaco-editor/esm/vs/language/css/css.worker',
'html.worker': 'monaco-editor/esm/vs/language/html/html.worker',
'ts.worker': 'monaco-editor/esm/vs/language/typescript/ts.worker'
},
output: {
globalObject: 'self',
filename: "[name].bundle.js",
path: outputDir,
},
mode: mode,
devtool: devtools[mode],
performance: {
hints: false,
},
target: targets[env] || targets.default,
devServer: {
static: {
directory: outputDir,
},
hot: false,
liveReload: false,
allowedHosts: "all",
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"],
fallback: {
// Allows the path Node.js module to be used in Weback bundled code.
"path": require.resolve("path-browserify"),
},
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.ttf$/,
use: ['file-loader']
},
{
test: /\.txt$/,
type: 'asset/source',
},
{
test: /\.tsx?$/,
loader: "ts-loader",
options: { transpileOnly: true },
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
plugins: [
new webpack.EnvironmentPlugin({
// Configure environment variables here.
ENVIRONMENT: env,
...processEnv,
}),
new ForkTsCheckerWebpackPlugin(),
// new ForkTsCheckerNotifierWebpackPlugin({ title: 'TypeScript', excludeWarnings: false }),
new CopyWebpackPlugin({
patterns: [
{
from: `./src/index.html`,
to: outputDir,
},
{
from: `./src/loading.html`,
to: outputDir,
},
{
from: `${__dirname}/node_modules/normalize.css/normalize.css`,
to: outputDir,
},
{
from: `${__dirname}/node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css`,
to: outputDir,
},
{
from: `${__dirname}/node_modules/@blueprintjs/core/lib/css/blueprint.css`,
to: outputDir,
},
{
from: `${__dirname}/styles`,
to: outputDir,
},
{
from: `${__dirname}/assets`,
to: outputDir,
},
],
}),
],
};
}