2023-01-06 17:18:20 +03:00
//@ts-check
'use strict'
const path = require ( 'path' )
const maven = require ( 'maven' )
const CopyPlugin = require ( 'copy-webpack-plugin' )
const webpack = require ( 'webpack' )
const mvnBuild = {
2024-07-26 09:34:51 +03:00
apply : compiler => {
compiler . hooks . beforeCompile . tapPromise ( 'MavenPlugin' , compilation => {
const mvn = maven . create ( { cwd : '.' } )
return mvn . execute ( [ 'package' ] , { skipTests : true } )
} )
} ,
2023-01-06 17:18:20 +03:00
}
const copyCluster = new CopyPlugin ( {
2024-07-26 09:34:51 +03:00
patterns : [
{
from : './target/nbm/clusters/extra/' ,
to : '../nbcode/enso4igv/' ,
} ,
] ,
2023-01-06 17:18:20 +03:00
} )
const copyLicense = new CopyPlugin ( {
2024-07-26 09:34:51 +03:00
patterns : [
{
from : '../../LICENSE' ,
to : '.' ,
} ,
] ,
2023-01-06 17:18:20 +03:00
} )
const entryExtension = {
2024-07-26 09:34:51 +03:00
extension : './src/main/vscode/extension.ts' , // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
2023-01-06 17:18:20 +03:00
}
/**@type {import('webpack').Configuration}*/
const config = {
2024-07-26 09:34:51 +03:00
target : 'node' , // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
2023-01-06 17:18:20 +03:00
2024-07-26 09:34:51 +03:00
plugins : [ mvnBuild , copyCluster , copyLicense ] ,
entry : entryExtension ,
output : {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path : path . resolve ( _ _dirname , 'dist' ) ,
filename : '[name].js' ,
libraryTarget : 'commonjs2' ,
devtoolModuleFilenameTemplate : '../[resource-path]' ,
} ,
devtool : 'source-map' ,
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/
bufferutil : 'bufferutil' ,
'utf-8-validate' : 'utf-8-validate' ,
} ,
resolve : {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions : [ '.ts' , '.js' ] ,
symlinks : false ,
} ,
module : {
rules : [
{
test : /\.ts$/ ,
exclude : /node_modules/ ,
include : path . resolve ( _ _dirname , 'src' ) ,
use : [
{
loader : 'ts-loader' ,
} ,
2023-01-06 17:18:20 +03:00
] ,
2024-07-26 09:34:51 +03:00
} ,
] ,
} ,
2023-01-06 17:18:20 +03:00
}
const devConf = {
2024-07-26 09:34:51 +03:00
target : 'node' , // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
2023-01-06 17:18:20 +03:00
2024-07-26 09:34:51 +03:00
plugins : [ mvnBuild , copyCluster , copyLicense , new webpack . AutomaticPrefetchPlugin ( ) ] ,
entry : entryExtension ,
output : {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path : path . resolve ( _ _dirname , 'dist' ) ,
filename : '[name].js' ,
libraryTarget : 'commonjs2' ,
devtoolModuleFilenameTemplate : '../[resource-path]' ,
} ,
devtool : 'source-map' ,
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/
bufferutil : 'bufferutil' ,
'utf-8-validate' : 'utf-8-validate' ,
} ,
resolve : {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions : [ '.ts' , '.js' ] ,
symlinks : false ,
cacheWithContext : false ,
} ,
module : {
rules : [
{
test : /\.ts$/ ,
exclude : /node_modules/ ,
include : path . resolve ( _ _dirname , 'src' ) ,
use : [
{
loader : 'ts-loader' ,
options : {
transpileOnly : true , // https://github.com/TypeStrong/ts-loader#faster-builds
2023-01-06 17:18:20 +03:00
} ,
2024-07-26 09:34:51 +03:00
} ,
2023-01-06 17:18:20 +03:00
] ,
2024-07-26 09:34:51 +03:00
} ,
] ,
} ,
optimization : {
minimize : false ,
} ,
cache : {
type : 'filesystem' ,
buildDependencies : {
// This makes all dependencies of this file - build dependencies
config : [ _ _filename ] ,
// By default webpack and loaders are build dependencies
2023-01-06 17:18:20 +03:00
} ,
2024-07-26 09:34:51 +03:00
} ,
2023-01-06 17:18:20 +03:00
}
// https://webpack.js.org/configuration/mode/#mode-none
module . exports = ( env , argv ) => {
2024-07-26 09:34:51 +03:00
if ( argv . mode === 'development' ) {
return devConf
}
2023-01-06 17:18:20 +03:00
2024-07-26 09:34:51 +03:00
if ( argv . mode === 'production' ) {
2023-01-06 17:18:20 +03:00
return config
2024-07-26 09:34:51 +03:00
}
return config
2023-01-06 17:18:20 +03:00
}