2020-05-02 23:44:08 +03:00
//@ts-check
'use strict' ;
const path = require ( 'path' ) ;
2020-09-20 20:57:38 +03:00
const webpack = require ( 'webpack' ) ;
2020-07-09 06:44:05 +03:00
const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' ) ;
2021-03-06 23:37:09 +03:00
const ForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
2022-12-06 06:08:15 +03:00
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
2020-05-02 23:44:08 +03:00
/**@type {import('webpack').Configuration}*/
const config = {
target : 'node' , // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode : 'production' ,
entry : './extension.ts' , // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output : {
// the bundle is stored in the 'out' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path : path . resolve ( _ _dirname , 'out' ) ,
filename : 'extension.js' ,
libraryTarget : 'commonjs2' ,
devtoolModuleFilenameTemplate : '../[resource-path]' ,
} ,
externals : {
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/
} ,
resolve : {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions : [ '.ts' , '.js' ] ,
2020-09-20 20:57:38 +03:00
alias : {
2020-12-14 23:04:03 +03:00
path : 'path-browserify' ,
2020-09-20 20:57:38 +03:00
platform : path . resolve ( _ _dirname , 'src' , 'platform' , 'node' ) ,
} ,
2020-05-02 23:44:08 +03:00
} ,
2021-02-09 00:24:43 +03:00
optimization : {
minimize : true ,
} ,
2020-05-02 23:44:08 +03:00
module : {
rules : [
{
test : /\.ts$/ ,
exclude : /node_modules/ ,
2020-07-09 06:44:05 +03:00
loader : 'ts-loader' ,
2021-03-06 23:37:09 +03:00
options : {
// Don't type check - ForkTsCheckerWebpackPlugin does this faster
transpileOnly : true ,
} ,
2020-05-02 23:44:08 +03:00
} ,
] ,
} ,
2020-09-20 20:57:38 +03:00
plugins : [
new CleanWebpackPlugin ( {
cleanOnceBeforeBuildPatterns : [ ] , // disable initial clean
} ) ,
2021-03-06 23:37:09 +03:00
new ForkTsCheckerWebpackPlugin ( ) ,
2022-12-06 06:08:15 +03:00
new CircularDependencyPlugin ( {
// exclude detection of files based on a RegExp
exclude : /node_modules/ ,
// include specific files based on a RegExp
include : /src/ ,
// add errors to webpack instead of warnings
failOnError : true ,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles : true ,
// set the current working directory for displaying module paths
cwd : process . cwd ( ) ,
} ) ,
2020-09-20 20:57:38 +03:00
] ,
2020-05-02 23:44:08 +03:00
} ;
2020-09-20 20:57:38 +03:00
/**@type {import('webpack').Configuration}*/
const nodelessConfig = {
target : 'webworker' , // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode : 'development' ,
entry : './extensionWeb.ts' , // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output : {
// the bundle is stored in the 'out' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path : path . resolve ( _ _dirname , 'out' ) ,
filename : 'extensionWeb.js' ,
libraryTarget : 'umd' ,
} ,
externals : {
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/
} ,
resolve : {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions : [ '.ts' , '.js' ] ,
alias : {
platform : path . resolve ( _ _dirname , 'src' , 'platform' , 'browser' ) ,
} ,
2021-09-04 23:43:51 +03:00
fallback : {
os : require . resolve ( 'os-browserify/browser' ) ,
path : require . resolve ( 'path-browserify' ) ,
process : require . resolve ( 'process/browser' ) ,
util : require . resolve ( 'util' ) ,
} ,
2020-09-20 20:57:38 +03:00
} ,
2021-02-09 00:24:43 +03:00
optimization : {
minimize : true ,
} ,
2020-09-20 20:57:38 +03:00
module : {
rules : [
{
test : /\.ts$/ ,
exclude : /node_modules/ ,
2021-03-06 23:37:09 +03:00
loader : 'ts-loader' ,
options : {
// Don't type check - ForkTsCheckerWebpackPlugin does this faster
transpileOnly : true ,
} ,
2020-09-20 20:57:38 +03:00
} ,
] ,
} ,
plugins : [
new webpack . IgnorePlugin ( {
resourceRegExp : /\/neovim$/ ,
} ) ,
new webpack . IgnorePlugin ( {
resourceRegExp : /\/imswitcher$/ ,
} ) ,
2021-01-30 01:23:12 +03:00
new webpack . IgnorePlugin ( {
resourceRegExp : /\/vimrc$/ ,
} ) ,
2020-09-20 20:57:38 +03:00
new webpack . IgnorePlugin ( {
resourceRegExp : /child_process$/ ,
} ) ,
2021-10-15 18:01:11 +03:00
new webpack . ProvidePlugin ( {
process : 'process/browser' , // util requires this internally
} ) ,
2021-03-06 23:37:09 +03:00
new ForkTsCheckerWebpackPlugin ( ) ,
2020-09-20 20:57:38 +03:00
] ,
} ;
module . exports = [ config , nodelessConfig ] ;