2018-12-20 12:14:07 +03:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright ( c ) Microsoft Corporation . All rights reserved .
* Licensed under the MIT License . See License . txt in the project root for license information .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
//@ts-check
'use strict' ;
2019-10-21 09:48:54 +03:00
const copyPlugin = require ( 'copy-webpack-plugin' ) ;
2018-12-20 12:14:07 +03:00
const failOnErrorsPlugin = require ( 'fail-on-errors-webpack-plugin' ) ;
2019-01-02 08:03:51 +03:00
const terserWebpackPlugin = require ( 'terser-webpack-plugin' ) ;
2018-12-20 12:14:07 +03:00
const path = require ( 'path' ) ;
const webpack = require ( 'webpack' ) ;
/**@type {import('webpack').Configuration}*/
const config = {
target : 'node' , // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
node : {
_ _dirname : false
} ,
entry : './src/extension.ts' , // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output : { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
2019-02-19 10:09:22 +03:00
path : path . resolve ( _ _dirname , 'dist' ) ,
2018-12-20 12:14:07 +03:00
filename : 'extension.js' ,
libraryTarget : "commonjs2" ,
2019-02-19 10:09:22 +03:00
devtoolModuleFilenameTemplate : "../[resource-path]" ,
2018-12-20 12:14:07 +03:00
} ,
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 : 'commonjs bufferutil' , // bufferutil and utf-8-validate are actually optional binary dependencies. Adding them to suppress the warning https://github.com/websockets/ws/issues/719
2019-02-20 05:56:48 +03:00
'utf-8-validate' : 'commonjs utf-8-validate'
2018-12-20 12:14:07 +03:00
} ,
resolve : { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
2019-09-24 06:57:11 +03:00
extensions : [ '.ts' , '.js' ] ,
// suppress warning: webpack + require handlebars error
alias : {
handlebars : 'handlebars/dist/handlebars.min.js'
}
2018-12-20 12:14:07 +03:00
} ,
module : {
rules : [
{
test : /\.ts$/ ,
exclude : /node_modules/ ,
use : [ {
2019-09-24 06:57:11 +03:00
loader : 'ts-loader'
2018-12-20 12:14:07 +03:00
} ]
} ,
{
test : /node_modules[/\\]mqtt[/\\]mqtt\.js$/i , // remove the #! which cannot be handled by Webpack
use : [ {
loader : 'shebang-loader'
} ]
} ,
{
test : /node_modules[/\\]mqtt[/\\]bin[/\\][ps]ub\.js$/i , // remove the #! which cannot be handled by Webpack
use : [ {
loader : 'shebang-loader'
} ]
}
]
} ,
plugins : [
// Ignore all locale files of moment.js, which can save 50KB
// https://webpack.js.org/plugins/ignore-plugin/#ignore-moment-locales
new webpack . IgnorePlugin ( /^\.\/locale$/ , /[\/\\]moment$/ ) ,
2019-10-21 09:48:54 +03:00
// Ignore the optional requirement of applicationinsights, which is not used in this extension
new webpack . IgnorePlugin ( /applicationinsights-native-metrics/ ) ,
2020-05-18 09:46:06 +03:00
// Ignore optional packages which used by vscode-extension-telemetry
new webpack . IgnorePlugin ( /@opentelemetry\/tracing/ ) ,
new webpack . IgnorePlugin ( /applicationinsights-native-metrics/ ) ,
2018-12-20 12:14:07 +03:00
// Suppress warnings of known dynamic require
new webpack . ContextReplacementPlugin (
/applicationinsights[\/\\]out[\/\\]AutoCollection/ ,
false ,
/$^/
) ,
new webpack . ContextReplacementPlugin (
/ms-rest[\/\\]lib/ ,
false ,
/$^/
) ,
new webpack . ContextReplacementPlugin (
/applicationinsights[\/\\]out[\/\\]Library/ ,
false ,
/$^/
) ,
// Pack node_modules/getos/logic/*.js
new webpack . ContextReplacementPlugin (
/getos/ ,
/logic[\/\\].*\.js/
) ,
2019-09-24 06:57:11 +03:00
// Express
2019-10-21 09:48:54 +03:00
new webpack . ContextReplacementPlugin (
2019-09-24 06:57:11 +03:00
/express[\/\\]lib/ ,
false ,
/$^/
) ,
2020-02-12 04:55:07 +03:00
// Numbro
new webpack . ContextReplacementPlugin (
/numbro/ ,
false ,
/$^/
) ,
2019-10-21 09:48:54 +03:00
// Copy required resources for Azure treeview
new copyPlugin ( [
path . join ( 'node_modules' , 'vscode-azureextensionui' , 'resources' , '**' , '*.svg' )
] ) ,
2018-12-20 12:14:07 +03:00
// Fail on warnings so that CI can report new warnings which require attention
new failOnErrorsPlugin ( {
failOnErrors : true ,
failOnWarnings : true ,
} )
2018-12-29 08:55:07 +03:00
] ,
optimization : {
2019-01-02 08:03:51 +03:00
minimizer : [
new terserWebpackPlugin ( {
terserOptions : {
2019-10-11 10:48:22 +03:00
mangle : false ,
2019-01-02 08:03:51 +03:00
keep _fnames : true
}
} )
]
2018-12-29 08:55:07 +03:00
}
2018-12-20 12:14:07 +03:00
}
module . exports = config ;