184 lines
5.9 KiB
JavaScript
184 lines
5.9 KiB
JavaScript
/**
|
|
* Don't touch this file. It will be regenerated by theia build.
|
|
* To customize webpack configuration change /mnt/data/foss.global/git.zone/ide/applications/remote-theia/webpack.config.js
|
|
*/
|
|
// @ts-check
|
|
const path = require('path');
|
|
const yargs = require('yargs');
|
|
const webpack = require('webpack');
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
const NativeWebpackPlugin = require('@theia/native-webpack-plugin');
|
|
const { MonacoWebpackPlugin } = require('@theia/native-webpack-plugin/lib/monaco-webpack-plugins.js');
|
|
|
|
const { mode } = yargs.option('mode', {
|
|
description: "Mode to use",
|
|
choices: ["development", "production"],
|
|
default: "production"
|
|
}).argv;
|
|
|
|
const production = mode === 'production';
|
|
|
|
/** @type {import('webpack').EntryObject} */
|
|
const commonJsLibraries = {};
|
|
for (const [entryPointName, entryPointPath] of Object.entries({
|
|
'backend-init-theia': '@theia/plugin-ext/lib/hosted/node/scanners/backend-init-theia',
|
|
'parcel-watcher': '@theia/filesystem/lib/node/parcel-watcher',
|
|
'plugin-vscode-init': '@theia/plugin-ext-vscode/lib/node/plugin-vscode-init',
|
|
|
|
})) {
|
|
commonJsLibraries[entryPointName] = {
|
|
import: require.resolve(entryPointPath),
|
|
library: {
|
|
type: 'commonjs2',
|
|
},
|
|
};
|
|
}
|
|
|
|
const ignoredResources = new Set();
|
|
|
|
if (process.platform !== 'win32') {
|
|
ignoredResources.add('@vscode/windows-ca-certs');
|
|
ignoredResources.add('@vscode/windows-ca-certs/build/Release/crypt32.node');
|
|
}
|
|
|
|
const nativePlugin = new NativeWebpackPlugin({
|
|
out: 'native',
|
|
trash: true,
|
|
ripgrep: true,
|
|
pty: true,
|
|
nativeBindings: {
|
|
drivelist: 'drivelist/build/Release/drivelist.node'
|
|
}
|
|
});
|
|
|
|
// Ensure that node-pty is correctly hoisted
|
|
try {
|
|
require.resolve('node-pty');
|
|
} catch {
|
|
console.error('"node-pty" dependency is not installed correctly. Ensure that it is available in the root node_modules directory.');
|
|
console.error('Exiting webpack build process.');
|
|
process.exit(1);
|
|
}
|
|
|
|
/** @type {import('webpack').Configuration} */
|
|
const config = {
|
|
mode,
|
|
devtool: mode === 'development' ? 'source-map' : false,
|
|
target: 'node',
|
|
node: {
|
|
global: false,
|
|
__filename: false,
|
|
__dirname: false
|
|
},
|
|
resolve: {
|
|
extensions: ['.js', '.json', '.wasm', '.node'],
|
|
},
|
|
output: {
|
|
filename: '[name].js',
|
|
path: path.resolve(__dirname, 'lib', 'backend'),
|
|
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]?[loaders]',
|
|
},
|
|
entry: {
|
|
// Main entry point of the Theia application backend:
|
|
'main': require.resolve('./src-gen/backend/main'),
|
|
// Theia's IPC mechanism:
|
|
'ipc-bootstrap': require.resolve('@theia/core/lib/node/messaging/ipc-bootstrap'),
|
|
// VS Code extension support:
|
|
'plugin-host': require.resolve('@theia/plugin-ext/lib/hosted/node/plugin-host'),
|
|
|
|
// Make sure the node-pty thread workers can be executed:
|
|
'worker/conoutSocketWorker': require.resolve('node-pty/lib/worker/conoutSocketWorker'),
|
|
'conpty_console_list_agent': require.resolve('node-pty/lib/conpty_console_list_agent'),
|
|
|
|
|
|
...commonJsLibraries
|
|
},
|
|
module: {
|
|
rules: [
|
|
// Make sure we can still find and load our native addons.
|
|
{
|
|
test: /\.node$/,
|
|
loader: 'node-loader',
|
|
options: {
|
|
name: 'native/[name].[ext]'
|
|
}
|
|
},
|
|
{
|
|
test: /\.d\.ts$/,
|
|
loader: 'ignore-loader'
|
|
},
|
|
{
|
|
test: /\.js$/,
|
|
enforce: 'pre',
|
|
loader: 'source-map-loader'
|
|
},
|
|
// node-pty uses a dynamic require which needs to be rewritten to work with webpack.
|
|
{
|
|
test: /node_modules[/\\]node-pty[/\\]lib[/\\]utils.js$/,
|
|
loader: 'string-replace-loader',
|
|
options: {
|
|
search: /require\(/,
|
|
replace: '__non_webpack_require__(',
|
|
flags: 'g'
|
|
}
|
|
},
|
|
// jsonc-parser exposes its UMD implementation by default, which
|
|
// confuses Webpack leading to missing js in the bundles.
|
|
{
|
|
test: /node_modules[\/](jsonc-parser)/,
|
|
loader: 'umd-compat-loader'
|
|
}
|
|
]
|
|
},
|
|
plugins: [
|
|
// Some native dependencies need special handling
|
|
nativePlugin,
|
|
// Optional node dependencies can be safely ignored
|
|
new webpack.IgnorePlugin({
|
|
checkResource: resource => ignoredResources.has(resource)
|
|
}),
|
|
new MonacoWebpackPlugin()
|
|
],
|
|
optimization: {
|
|
// Split and reuse code across the various entry points
|
|
splitChunks: {
|
|
chunks: 'all'
|
|
},
|
|
// Only minimize if we run webpack in production mode
|
|
minimize: production,
|
|
minimizer: [
|
|
new TerserPlugin({
|
|
exclude: /^(lib|builtins)\//
|
|
})
|
|
]
|
|
},
|
|
ignoreWarnings: [
|
|
// Some packages do not have source maps, that's ok
|
|
/Failed to parse source map/,
|
|
// require with expressions are not supported
|
|
/the request of a dependency is an expression/,
|
|
// Some packages use dynamic requires, we can safely ignore them (they are handled by the native webpack plugin)
|
|
/require function is used in a way in which dependencies cannot be statically extracted/, {
|
|
module: /yargs/
|
|
}, {
|
|
module: /node-pty/
|
|
}, {
|
|
module: /require-main-filename/
|
|
}, {
|
|
module: /ws/
|
|
}, {
|
|
module: /express/
|
|
}, {
|
|
module: /cross-spawn/
|
|
}, {
|
|
module: /@parcel\/watcher/
|
|
}
|
|
]
|
|
};
|
|
|
|
module.exports = {
|
|
config,
|
|
nativePlugin,
|
|
ignoredResources
|
|
};
|