Skip to content

Commit 88d7eaf

Browse files
committed
Make two webpack configurations
1 parent 114ed92 commit 88d7eaf

1 file changed

Lines changed: 57 additions & 40 deletions

File tree

webpack.config.js

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,68 @@
88
const path = require('path')
99
const webpack = require('webpack')
1010

11-
/**@type {import('webpack').Configuration}*/
12-
const config = {
13-
target: 'node', // "webworker" for web or "node" for desktop
11+
{
12+
require.resolve('assert')
13+
}
14+
15+
/** @typedef {import('webpack').Configuration} WebpackConfig **/
16+
17+
function createExtensionConfig ({ target, output, plugins }) {
18+
return {
19+
target,
20+
entry: './src/extension.ts',
21+
output,
22+
devtool: 'source-map',
23+
externals: {
24+
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/
25+
},
26+
resolve: {
27+
mainFields: ['browser', 'module', 'main'],
28+
extensions: ['.ts'],
29+
alias: {},
30+
fallback: {}
31+
},
32+
module: {
33+
rules: [
34+
{
35+
test: /\.ts$/,
36+
exclude: /node_modules/,
37+
use: [
38+
{
39+
loader: 'ts-loader'
40+
}
41+
]
42+
}
43+
]
44+
},
45+
plugins: plugins || []
46+
}
47+
}
1448

15-
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
49+
const nodeExtensionConfig = createExtensionConfig({
50+
target: 'node',
1651
output: {
17-
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
1852
path: path.resolve(__dirname, 'dist'),
1953
filename: 'extension.js',
2054
libraryTarget: 'commonjs2',
2155
devtoolModuleFilenameTemplate: '../[resource-path]'
2256
},
23-
devtool: 'source-map',
24-
externals: {
25-
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/
26-
},
27-
resolve: {
28-
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
29-
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
30-
extensions: ['.ts'],
31-
alias: {
32-
// provides alternate implementation for node module and source files
33-
},
34-
fallback: {
35-
// Webpack 5 no longer polyfills Node.js core modules automatically.
36-
// see https://webpack.js.org/configuration/resolve/#resolvefallback
37-
// for the list of Node.js core module polyfills.
38-
path: false,
39-
child_process: false,
40-
util: false
41-
// add other Node.js modules as needed
42-
}
57+
plugins: []
58+
})
59+
60+
const webExtensionConfig = createExtensionConfig({
61+
target: 'webworker',
62+
output: {
63+
filename: '[name].js',
64+
path: path.join(__dirname, './dist/web'),
65+
libraryTarget: 'commonjs',
66+
devtoolModuleFilenameTemplate: '../../[resource-path]'
4367
},
44-
module: {
45-
rules: [
46-
{
47-
test: /\.ts$/,
48-
exclude: /node_modules/,
49-
use: [
50-
{
51-
loader: 'ts-loader'
52-
}
53-
]
54-
}
55-
]
56-
}
57-
}
58-
module.exports = config
68+
plugins: [
69+
new webpack.ProvidePlugin({
70+
process: 'process/browser'
71+
})
72+
]
73+
})
74+
75+
module.exports = [webExtensionConfig, nodeExtensionConfig]

0 commit comments

Comments
 (0)