Skip to content

Commit 01365db

Browse files
committed
webpack - more defaults for extensions
1 parent 7b5dc58 commit 01365db

5 files changed

Lines changed: 83 additions & 20 deletions

File tree

extensions/emmet/extension.webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
'use strict';
77

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

1010
const myConfig = {
11+
context: __dirname,
1112
entry: {
1213
extension: './src/extension.ts',
1314
},
1415
externals: {
15-
'vscode': 'commonjs vscode', // ignored because it doesn't exist
1616
'@emmetio/css-parser': 'commonjs @emmetio/css-parser',
1717
'@emmetio/html-matcher': 'commonjs @emmetio/html-matcher',
1818
'@emmetio/math-expression': 'commonjs @emmetio/math-expression',
@@ -21,4 +21,4 @@ const myConfig = {
2121
},
2222
};
2323

24-
module.exports = { ...sharedConfig(__dirname), ...myConfig };
24+
module.exports = withDefaults(myConfig);

extensions/git/extension.webpack.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
'use strict';
77

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

1111
const myConfig = {
12+
context: __dirname,
1213
node: {
1314
__dirname: false // leave the __dirname-behaviour intact
1415
},
@@ -18,12 +19,10 @@ const myConfig = {
1819
},
1920
plugins: [
2021
new CopyWebpackPlugin([
21-
{ from: './out/*.sh', to: '[name].sh' },
22-
{ from: './out/nls.*.json', to: '[name].json' }
22+
{ from: './out/*.sh', to: '[name].sh' }
2323
])
2424
],
2525
externals: {
26-
'vscode': 'commonjs vscode', // ignored because it doesn't exist
2726
"byline": 'commonjs byline',
2827
"file-type": 'commonjs file-type',
2928
"iconv-lite": 'commonjs iconv-lite',
@@ -34,4 +33,4 @@ const myConfig = {
3433
},
3534
};
3635

37-
module.exports = { ...sharedConfig(__dirname), ...myConfig };
36+
module.exports = withDefaults(myConfig);

extensions/shared.webpack.config.js

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
'use strict';
77

88
const path = require('path');
9+
const CopyWebpackPlugin = require('copy-webpack-plugin');
10+
const merge = require('merge-options');
911

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,
12+
module.exports = function withDefaults(extConfig) {
13+
let defaultConfig = {
1814
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
1915
target: 'node', // extensions run in a node context
2016
resolve: {
@@ -43,14 +39,75 @@ module.exports = function (extensionDir) {
4339
}]
4440
}]
4541
},
42+
plugins: [
43+
new CopyWebpackPlugin([{ from: './out/nls.*.json', to: '[name].json' }]) // copy nls files
44+
],
45+
externals: {
46+
'vscode': 'commonjs vscode', // ignored because it doesn't exist
47+
},
4648
output: {
4749
// all output goes into `dist`.
4850
// packaging depends on that and this must always be like it
4951
filename: '[name].js',
50-
path: path.join(extensionDir, 'dist'),
52+
path: path.join(extConfig.context, 'dist'),
5153
libraryTarget: "commonjs",
5254
},
5355
// yes, really source maps
5456
devtool: 'source-map'
55-
};
56-
};
57+
}
58+
59+
return merge(defaultConfig, extConfig);
60+
}
61+
62+
// /**
63+
// * Function that must be invoked with __dirname and that
64+
// * returns a good default configuation for extensions that
65+
// * want to do webpack
66+
// */
67+
// module.exports = function (extensionDir) {
68+
// return {
69+
// context: extensionDir,
70+
// mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
71+
// target: 'node', // extensions run in a node context
72+
// resolve: {
73+
// mainFields: ['main'], // prefer the main-entry of package.json files
74+
// extensions: ['.ts', '.js'] // support ts-files and js-files
75+
// },
76+
// module: {
77+
// rules: [{
78+
// test: /\.ts$/,
79+
// exclude: /node_modules/,
80+
// use: [{
81+
// // vscode-nls-dev loader:
82+
// // * rewrite nls-calls
83+
// loader: 'vscode-nls-dev/lib/webpack-loader'
84+
// }, {
85+
// // configure TypeScript loader:
86+
// // * only transpile because we have a separate compilation pipeline
87+
// // * enable sources maps for end-to-end source maps
88+
// loader: 'ts-loader',
89+
// options: {
90+
// transpileOnly: true,
91+
// compilerOptions: {
92+
// "sourceMap": true,
93+
// }
94+
// }
95+
// }]
96+
// }]
97+
// },
98+
// plugins: [
99+
// new CopyWebpackPlugin([
100+
// { from: './out/nls.*.json', to: '[name].json' }
101+
// ])
102+
// ],
103+
// output: {
104+
// // all output goes into `dist`.
105+
// // packaging depends on that and this must always be like it
106+
// filename: '[name].js',
107+
// path: path.join(extensionDir, 'dist'),
108+
// libraryTarget: "commonjs",
109+
// },
110+
// // yes, really source maps
111+
// devtool: 'source-map'
112+
// };
113+
// };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"istanbul": "^0.3.17",
103103
"jsdom-no-contextify": "^3.1.0",
104104
"lazy.js": "^0.4.2",
105+
"merge-options": "^1.0.1",
105106
"mime": "^1.4.1",
106107
"minimatch": "^2.0.10",
107108
"mkdirp": "^0.5.0",

yarn.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3909,7 +3909,7 @@ is-path-inside@^1.0.0:
39093909
dependencies:
39103910
path-is-inside "^1.0.1"
39113911

3912-
is-plain-obj@^1.0.0:
3912+
is-plain-obj@^1.0.0, is-plain-obj@^1.1:
39133913
version "1.1.0"
39143914
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
39153915

@@ -4724,6 +4724,12 @@ merge-descriptors@1.0.1:
47244724
version "1.0.1"
47254725
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
47264726

4727+
merge-options@^1.0.1:
4728+
version "1.0.1"
4729+
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-1.0.1.tgz#2a64b24457becd4e4dc608283247e94ce589aa32"
4730+
dependencies:
4731+
is-plain-obj "^1.1"
4732+
47274733
merge-stream@^1.0.0:
47284734
version "1.0.1"
47294735
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"

0 commit comments

Comments
 (0)