forked from renpy/vscode-language-renpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
108 lines (98 loc) · 3.57 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import * as path from "path";
import { Compiler, Configuration, WebpackPluginInstance } from "webpack";
import CopyWebpackPlugin from "copy-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
const PATHS = {
src: path.join(__dirname, "src"),
dist: path.join(__dirname, "dist"),
cache: path.join(__dirname, "node_modules/.cache/webpack"),
node: path.join(__dirname, "node_modules"),
};
export const basePlugins: (((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance)[] = [
new CopyWebpackPlugin({
patterns: [{ from: "src", to: ".", globOptions: { ignore: ["**/test/**", "**/*.ts"] }, noErrorOnMissing: true }],
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: "write-references",
},
}),
];
export const baseConfig: Configuration = {
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
filename: "extension.js",
path: PATHS.dist,
library: {
type: "commonjs2",
},
devtoolModuleFilenameTemplate: "../[resource-path]", // Removes the webpack:/// prefix from source maps
},
module: {
rules: [
{
test: /\.ts$/,
include: PATHS.src,
use: [
{
// configure TypeScript loader:
// * enable sources maps for end-to-end source maps
loader: "ts-loader",
options: {
compilerOptions: {
sourceMap: true,
},
},
},
],
},
],
},
externals: {
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
},
entry: {
extension: path.join(PATHS.src, "extension.ts"),
},
devtool: "source-map",
cache: {
type: "filesystem",
buildDependencies: {
// This makes all dependencies of this file - build dependencies
config: [__filename],
// By default webpack and loaders are build dependencies
},
cacheDirectory: PATHS.cache,
},
plugins: [...basePlugins],
watchOptions: {
// for some systems, watching many files can result in a lot of CPU or memory usage
// https://webpack.js.org/configuration/watch/#watchoptionsignored
// don't use this pattern, if you have a monorepo with linked packages
ignored: /node_modules/,
},
optimization: {
splitChunks: {
chunks: "async",
},
},
stats: "normal",
};
export const nodeConfig: Configuration = {
target: "node", // extensions run in a node context
node: {
__dirname: false, // leave the __dirname-behaviour intact
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
mainFields: ["module", "main"],
extensions: [".ts", ".js"], // support ts-files and js-files
},
...baseConfig,
};
export default nodeConfig;