-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
73 lines (65 loc) · 2.27 KB
/
webpack.config.js
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
//@ts-check
'use strict';
const path = require('path');
const webpack = require('webpack');
/**@type {import('webpack').Configuration}*/
// eslint-disable-next-line no-undef
module.exports = {
target: 'webworker', // compatibility with VS Code web
entry: './src/extension.ts',
output: {
// eslint-disable-next-line no-undef
path: path.resolve(__dirname),
filename: 'main.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
devtool: 'source-map',
externals: { // these modules should not be bundled
vscode: 'commonjs vscode',
},
resolve: {
extensions: ['.ts', '.html'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
{
test: /\.html$/i,
loader: "html-loader",
options: {
preprocessor: async (content, loaderContext) => {
const $ = require('cheerio').load(content);
const fs = require('fs');
const path = require('path');
const read = (p) => fs.readFileSync(path.resolve(loaderContext.context, p));
try {
$('script').each(function () {
$(this).text(read($(this).attr("src")));
$(this).removeAttr("src");
});
$('link[rel="stylesheet"]').replaceWith(function () {
return $('<style>').text(read($(this).attr("href")));
});
} catch (error) {
await loaderContext.emitError(error);
return content;
}
return $.html();
}
}
}
]
},
plugins: [
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10#issuecomment-615877593
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
]
};