Skip to content

Commit 1115196

Browse files
committed
add a shared webpack conifg
1 parent 7c9b48b commit 1115196

3 files changed

Lines changed: 63 additions & 67 deletions

File tree

extensions/emmet/extension.webpack.config.js

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,20 @@
55

66
'use strict';
77

8-
const path = require('path');
8+
const sharedConfig = require('../shared.webpack.config');
99

10-
module.exports = {
11-
// mode: 'production',
12-
// stats: 'errors-only',
13-
mode: 'none',
14-
context: __dirname,
15-
target: 'node',
10+
const myConfig = {
1611
entry: {
1712
extension: './src/extension.ts',
1813
},
19-
resolve: {
20-
mainFields: ['main'],
21-
extensions: [".ts", ".js"]
22-
},
23-
module: {
24-
rules: [{
25-
test: /\.ts$/,
26-
exclude: /node_modules/,
27-
use: [{
28-
loader: 'ts-loader',
29-
options: {
30-
transpileOnly: true,
31-
compilerOptions: {
32-
"sourceMap": true,
33-
}
34-
}
35-
}]
36-
}]
37-
},
38-
output: {
39-
filename: '[name].js',
40-
path: path.join(__dirname, 'dist'),
41-
libraryTarget: "commonjs",
42-
},
43-
devtool: 'source-map',
4414
externals: {
45-
'vscode': 'commonjs vscode',
15+
'vscode': 'commonjs vscode', // ignored because it doesn't exist
4616
'@emmetio/css-parser': 'commonjs @emmetio/css-parser',
4717
'@emmetio/html-matcher': 'commonjs @emmetio/html-matcher',
4818
'@emmetio/math-expression': 'commonjs @emmetio/math-expression',
4919
'image-size': 'commonjs image-size',
5020
'vscode-emmet-helper': 'commonjs vscode-emmet-helper',
5121
},
5222
};
23+
24+
module.exports = { ...sharedConfig(__dirname), ...myConfig };

extensions/git/extension.webpack.config.js

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,25 @@
55

66
'use strict';
77

8-
const path = require('path');
8+
const sharedConfig = require('../shared.webpack.config');
99
const CopyWebpackPlugin = require('copy-webpack-plugin');
1010

11-
module.exports = {
12-
// mode: 'production',
13-
// stats: 'errors-only',
14-
mode: 'none',
15-
context: __dirname,
16-
target: 'node',
11+
const myConfig = {
1712
node: {
18-
__dirname: false
13+
__dirname: false // leave the __dirname-behaviour intact
1914
},
2015
entry: {
2116
main: './src/main.ts',
2217
['askpass-main']: './src/askpass-main.ts'
2318
},
24-
resolve: {
25-
mainFields: ['main'],
26-
extensions: [".ts", ".js"]
27-
},
28-
module: {
29-
rules: [{
30-
test: /\.ts$/,
31-
exclude: /node_modules/,
32-
use: [{
33-
loader: 'ts-loader',
34-
options: {
35-
transpileOnly: true,
36-
compilerOptions: {
37-
"sourceMap": true,
38-
}
39-
}
40-
}]
41-
}]
42-
},
43-
output: {
44-
filename: '[name].js',
45-
path: path.join(__dirname, 'dist'),
46-
libraryTarget: "commonjs"
47-
},
4819
plugins: [
4920
new CopyWebpackPlugin([
5021
{ from: './out/*.sh', to: '[name].sh' },
5122
{ from: './out/nls.*.json', to: '[name].json' }
5223
])
5324
],
54-
devtool: 'source-map',
5525
externals: {
56-
'vscode': 'commonjs vscode',
26+
'vscode': 'commonjs vscode', // ignored because it doesn't exist
5727
"byline": 'commonjs byline',
5828
"file-type": 'commonjs file-type',
5929
"iconv-lite": 'commonjs iconv-lite',
@@ -63,3 +33,5 @@ module.exports = {
6333
"which": 'commonjs which',
6434
},
6535
};
36+
37+
module.exports = { ...sharedConfig(__dirname), ...myConfig };
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
const path = require('path');
9+
10+
/**
11+
* Function that must be invoked with __dirname and that
12+
* returns a good default configuation for extensions that
13+
* want to do webpack
14+
*/
15+
module.exports = function (extensionDir) {
16+
return {
17+
context: extensionDir,
18+
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
19+
target: 'node', // extensions run in a node context
20+
resolve: {
21+
mainFields: ['main'], // prefer the main-entry of package.json files
22+
extensions: [".ts", ".js"] // support ts-files and js-files
23+
},
24+
module: {
25+
rules: [{
26+
// configure TypeScript loader:
27+
// * only transpile because we have a separate compilation pipeline
28+
// * enable sources maps for end-to-end source maps
29+
test: /\.ts$/,
30+
exclude: /node_modules/,
31+
use: [{
32+
loader: 'ts-loader',
33+
options: {
34+
transpileOnly: true,
35+
compilerOptions: {
36+
"sourceMap": true,
37+
}
38+
}
39+
}]
40+
}]
41+
},
42+
output: {
43+
// all output goes into `dist`.
44+
// packaging depends on that and this must always be like it
45+
filename: '[name].js',
46+
path: path.join(extensionDir, 'dist'),
47+
libraryTarget: "commonjs",
48+
},
49+
// yes, really source maps
50+
devtool: 'source-map'
51+
};
52+
};

0 commit comments

Comments
 (0)