used shared webpack-config for browser

This commit is contained in:
Martin Aeschlimann 2020-06-25 23:21:56 +02:00
parent 5e870a6627
commit 16be2c9885
21 changed files with 97 additions and 184 deletions

View file

@ -7,27 +7,15 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/configurationEditingMain.ts'
},
output: {
filename: 'configurationEditingMain.js'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -13,7 +13,7 @@
"onLanguage:jsonc"
],
"main": "./out/configurationEditingMain",
"browser": "./dist/configurationEditingMain",
"browser": "./dist/browser/configurationEditingMain",
"scripts": {
"compile": "gulp compile-extension:configuration-editing",
"watch": "gulp watch-extension:configuration-editing"

View file

@ -7,11 +7,10 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const path = require('path');
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: path.join(__dirname, 'client'),
entry: {
extension: './src/browser/cssClientMain.ts'
@ -19,16 +18,5 @@ const clientConfig = withDefaults({
output: {
filename: 'cssClientMain.js',
path: path.join(__dirname, 'client', 'dist', 'browser')
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -7,11 +7,10 @@
'use strict';
const withDefaults = require('../../shared.webpack.config');
const withBrowserDefaults = require('../../shared.webpack.config').browser;
const path = require('path');
const serverConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/cssServerMain.ts',
@ -20,16 +19,5 @@ const serverConfig = withDefaults({
filename: 'cssServerMain.js',
path: path.join(__dirname, 'dist', 'browser'),
libraryTarget: 'var'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../../build/polyfills/vscode-nls.js')
}
}
});
serverConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = serverConfig;

View file

@ -7,11 +7,10 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const path = require('path');
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: path.join(__dirname, 'client'),
entry: {
extension: './src/browser/htmlClientMain.ts'
@ -19,16 +18,5 @@ const clientConfig = withDefaults({
output: {
filename: 'htmlClientMain.js',
path: path.join(__dirname, 'client', 'dist', 'browser')
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -7,36 +7,25 @@
'use strict';
const withDefaults = require('../../shared.webpack.config');
const withBrowserDefaults = require('../../shared.webpack.config').browser;
const path = require('path');
const serverConfig = withDefaults({
target: 'webworker',
const serverConfig = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/htmlServerMain.ts',
},
output: {
filename: 'htmlServerMain.js',
path: path.join(__dirname, 'dist', 'browser'),
libraryTarget: 'var'
},
performance: {
hints: false
},
optimization: {
splitChunks: {
chunks: "async"
}
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../../build/polyfills/vscode-nls.js')
}
}
});
serverConfig.module.rules[0].use.shift(); // remove nls loader
serverConfig.module.noParse = /typescript\/lib\/typescript\.js/;
serverConfig.module.rules.push({
test: /javascriptLibs.ts$/,

View file

@ -7,23 +7,11 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
module.exports = withBrowserDefaults({
context: __dirname,
target: 'webworker',
entry: {
extension: './src/extension.ts'
},
resolve: {
alias: {
'vscode-extension-telemetry': path.resolve(__dirname, '../../build/polyfills/vscode-extension-telemetry.js'),
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js'),
},
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -16,7 +16,7 @@
"vscode": "^1.39.0"
},
"main": "./out/extension",
"browser": "./dist/extension.js",
"browser": "./dist/browser/extension.js",
"categories": [
"Other"
],

View file

@ -7,10 +7,10 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const path = require('path');
const clientConfig = withDefaults({
module.exports = withBrowserDefaults({
target: 'webworker',
context: path.join(__dirname, 'client'),
entry: {
@ -19,16 +19,5 @@ const clientConfig = withDefaults({
output: {
filename: 'jsonClientMain.js',
path: path.join(__dirname, 'client', 'dist', 'browser')
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -7,11 +7,10 @@
'use strict';
const withDefaults = require('../../shared.webpack.config');
const withBrowserDefaults = require('../../shared.webpack.config').browser;
const path = require('path');
const serverConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/jsonServerMain.ts',
@ -20,16 +19,5 @@ const serverConfig = withDefaults({
filename: 'jsonServerMain.js',
path: path.join(__dirname, 'dist', 'browser'),
libraryTarget: 'var'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../../build/polyfills/vscode-nls.js')
}
}
});
serverConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = serverConfig;

View file

@ -7,26 +7,11 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
module.exports = withBrowserDefaults({
context: __dirname,
target: 'webworker',
entry: {
extension: './src/extension.ts'
},
resolve: {
alias: {
'vscode-extension-telemetry': path.resolve(__dirname, '../../build/polyfills/vscode-extension-telemetry.js'),
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js'),
},
},
performance: {
hints: false
},
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -12,7 +12,7 @@
"vscode": "^1.20.0"
},
"main": "./out/extension",
"browser": "./dist/extension.js",
"browser": "./dist/browser/extension",
"categories": [
"Programming Languages"
],

View file

@ -7,27 +7,14 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/mergeConflictMain.ts'
},
output: {
filename: 'mergeConflictMain.js'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -17,7 +17,7 @@
"*"
],
"main": "./out/mergeConflictMain",
"browser": "./dist/mergeConflictMain",
"browser": "./dist/mergeConflictBrowserMain",
"scripts": {
"compile": "gulp compile-extension:merge-conflict",
"watch": "gulp watch-extension:merge-conflict"

View file

@ -7,11 +7,9 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/npmBrowserMain.ts'
@ -19,18 +17,7 @@ const clientConfig = withDefaults({
output: {
filename: 'npmBrowserMain.js'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
},
node: {
'child_process': 'empty'
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -28,7 +28,7 @@
"@types/node": "^12.11.7"
},
"main": "./out/npmMain",
"browser": "./dist/npmBrowserMain",
"browser": "./dist/browser/npmBrowserMain",
"activationEvents": [
"onCommand:workbench.action.tasks.runTask",
"onCommand:npm.runScriptFromFolder",

View file

@ -7,27 +7,14 @@
'use strict';
const withDefaults = require('../shared.webpack.config');
const path = require('path');
const withBrowserDefaults = require('../shared.webpack.config').browser;
const clientConfig = withDefaults({
target: 'webworker',
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/pythonMain.ts'
},
output: {
filename: 'pythonMain.js'
},
performance: {
hints: false
},
resolve: {
alias: {
'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js')
}
}
});
clientConfig.module.rules[0].use.shift(); // remove nls loader
module.exports = clientConfig;

View file

@ -8,7 +8,7 @@
"engines": { "vscode": "*" },
"activationEvents": ["onLanguage:python"],
"main": "./out/pythonMain",
"browser": "./dist/pythonMain",
"browser": "./dist/browser/pythonMain",
"extensionKind": [ "ui", "workspace" ],
"contributes": {
"languages": [{

View file

@ -14,7 +14,7 @@ const merge = require('merge-options');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { NLSBundlePlugin } = require('vscode-nls-dev/lib/webpack-bundler');
module.exports = function withDefaults(/**@type WebpackConfig*/extConfig) {
function withNodeDefaults(/**@type WebpackConfig*/extConfig) {
// Need to find the top-most `package.json` file
const folderName = path.relative(__dirname, extConfig.context).split(/[\\\/]/)[0];
const pkgPath = path.join(__dirname, folderName, 'package.json');
@ -78,3 +78,65 @@ module.exports = function withDefaults(/**@type WebpackConfig*/extConfig) {
return merge(defaultConfig, extConfig);
};
function withBrowserDefaults(/**@type WebpackConfig*/extConfig) {
/** @type WebpackConfig */
let defaultConfig = {
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
target: 'webworker', // extensions run in a webworker context
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
'vscode-nls': path.resolve(__dirname, '../build/polyfills/vscode-nls.js'),
'vscode-extension-telemetry': path.resolve(__dirname, '../build/polyfills/vscode-extension-telemetry.js')
}
},
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
use: [{
// configure TypeScript loader:
// * enable sources maps for end-to-end source maps
loader: 'ts-loader',
options: {
compilerOptions: {
'sourceMap': true,
}
}
}]
}]
},
externals: {
'vscode': 'commonjs vscode', // ignored because it doesn't exist
},
performance: {
hints: false
},
output: {
// all output goes into `dist`.
// packaging depends on that and this must always be like it
filename: '[name].js',
path: path.join(extConfig.context, 'dist', 'browser'),
libraryTarget: 'commonjs',
},
// yes, really source maps
devtool: 'source-map',
plugins: [
// @ts-expect-error
new CopyWebpackPlugin([
{ from: 'src', to: '.', ignore: ['**/test/**', '*.ts'] }
]),
]
};
return merge(defaultConfig, extConfig);
};
module.exports = withNodeDefaults;
module.exports.node = withNodeDefaults;
module.exports.browser = withBrowserDefaults;

View file

@ -7,11 +7,10 @@
'use strict';
const path = require('path');
const withDefaults = require('../shared.webpack.config');
const withBrowserDefaults = require('../shared.webpack.config').browser;
module.exports = withDefaults({
module.exports = withBrowserDefaults({
context: __dirname,
target: 'webworker',
node: false,
entry: {
extension: './src/extension.ts',

View file

@ -11,7 +11,7 @@
"onFileSystem:github",
"onDebug"
],
"browser": "./dist/extension",
"browser": "./dist/browser/extension",
"main": "./out/extension",
"engines": {
"vscode": "^1.25.0"