-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
135 lines (123 loc) · 4.77 KB
/
Copy pathwebpack.config.ts
File metadata and controls
135 lines (123 loc) · 4.77 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
import CopyWebpackPlugin from "copy-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import * as path from "path";
import { Compiler, Configuration, WebpackPluginInstance } from "webpack";
import WebpackShellPlugin from "webpack-shell-plugin-next";
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"),
scripts: path.join(__dirname, "scripts"),
};
const webpackShellPlugin = new WebpackShellPlugin({
onBeforeCompile: {
scripts: [`npx @manzt/uv run --directory ${PATHS.scripts} generate.py`],
blocking: true,
parallel: false,
},
});
class WatchYamlFilesPlugin {
apply(compiler: Compiler) {
compiler.hooks.afterCompile.tap("WatchYamlFilesPlugin", (compilation) => {
compilation.fileDependencies.add(path.join(__dirname, "syntaxes", "renpy.atl.tmLanguage.yaml"));
compilation.fileDependencies.add(path.join(__dirname, "syntaxes", "renpy.screen.tmLanguage.yaml"));
compilation.fileDependencies.add(path.join(__dirname, "syntaxes", "renpy.style.tmLanguage.yaml"));
compilation.fileDependencies.add(path.join(__dirname, "syntaxes", "renpy.test.tmLanguage.yaml"));
compilation.fileDependencies.add(path.join(__dirname, "syntaxes", "renpy.tmLanguage.yaml"));
});
}
}
export const basePlugins: (((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance)[] = [
new WatchYamlFilesPlugin(),
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: [webpackShellPlugin, ...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
alias: {
// Map the 'src' path to the actual src directory
src: path.resolve(__dirname, "src"),
},
},
...baseConfig,
};
export default nodeConfig;