2023-04-14 08:05:41 +08:00
//@ts-check
2023-11-09 18:02:57 +08:00
"use strict" ;
2023-04-14 08:05:41 +08:00
2023-11-09 18:02:57 +08:00
const path = require ( "path" ) ;
const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
const { DefinePlugin } = require ( "webpack" ) ;
const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
2023-12-13 15:06:05 +08:00
const { CleanWebpackPlugin } = require ( "clean-webpack-plugin" ) ;
2023-04-14 08:05:41 +08:00
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
const extensionConfig = {
2023-11-09 18:02:57 +08:00
name : "vscode extension" ,
target : "node" , // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode : "none" , // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
2023-04-14 08:05:41 +08:00
2023-11-09 18:02:57 +08:00
entry : "./src/extension.ts" , // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
2023-05-05 23:08:48 +08:00
2023-04-14 08:05:41 +08:00
output : {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
2023-11-09 18:02:57 +08:00
path : path . resolve ( _ _dirname , "dist" ) ,
filename : "extension.js" ,
libraryTarget : "commonjs2" ,
2023-04-14 08:05:41 +08:00
} ,
externals : {
2023-11-09 18:02:57 +08:00
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/
2023-04-14 08:05:41 +08:00
// modules added here also need to be added in the .vscodeignore file
} ,
resolve : {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
2023-11-09 18:02:57 +08:00
extensions : [ ".ts" , ".json" ] ,
2023-05-05 23:08:48 +08:00
} ,
module : {
rules : [
{
test : /\.ts?$/ ,
exclude : /node_modules/ ,
use : [
{
2023-11-09 18:02:57 +08:00
loader : "babel-loader" ,
2023-05-05 23:08:48 +08:00
options : {
presets : [
2023-11-09 18:02:57 +08:00
"@babel/preset-env" ,
"@babel/preset-react" ,
"@babel/preset-typescript" ,
] ,
} ,
2023-05-05 23:08:48 +08:00
} ,
{
2023-11-09 18:02:57 +08:00
loader : "ts-loader" ,
} ,
] ,
2023-05-05 23:08:48 +08:00
} ,
2023-11-09 18:02:57 +08:00
] ,
2023-05-05 23:08:48 +08:00
} ,
2023-11-09 18:02:57 +08:00
devtool : "nosources-source-map" ,
2023-05-05 23:08:48 +08:00
infrastructureLogging : {
level : "log" , // enables logging required for problem matchers
} ,
2023-12-13 15:06:05 +08:00
plugins : [
new CleanWebpackPlugin ( )
] ,
2023-05-05 23:08:48 +08:00
} ;
/** @type WebpackConfig */
const webviewConfig = {
2023-11-09 18:02:57 +08:00
name : "webview" ,
target : "web" ,
mode : "development" ,
2023-05-05 23:08:48 +08:00
2023-11-09 18:02:57 +08:00
entry : "./src/index.tsx" ,
2023-05-05 23:08:48 +08:00
output : {
2023-11-09 18:02:57 +08:00
path : path . resolve ( _ _dirname , "dist" ) ,
filename : "index.js" ,
publicPath : "/" ,
2023-05-05 23:08:48 +08:00
} ,
resolve : {
2023-11-09 18:02:57 +08:00
extensions : [ ".ts" , ".tsx" , ".js" , ".json" ] ,
2023-06-13 17:03:48 +08:00
alias : {
2023-11-09 18:02:57 +08:00
"@" : path . resolve ( _ _dirname , "src/" ) ,
2023-06-13 17:03:48 +08:00
} ,
2023-04-14 08:05:41 +08:00
} ,
module : {
rules : [
{
2023-05-04 16:09:19 +08:00
test : /\.tsx?$/ ,
2023-04-14 08:05:41 +08:00
exclude : /node_modules/ ,
use : [
2023-05-04 16:09:19 +08:00
{
2023-11-09 18:02:57 +08:00
loader : "babel-loader" ,
2023-05-04 16:09:19 +08:00
options : {
presets : [
2023-11-09 18:02:57 +08:00
"@babel/preset-env" ,
"@babel/preset-react" ,
"@babel/preset-typescript" ,
] ,
} ,
2023-05-04 16:09:19 +08:00
} ,
2023-04-14 08:05:41 +08:00
{
2023-11-09 18:02:57 +08:00
loader : "ts-loader" ,
} ,
] ,
2023-05-04 16:09:19 +08:00
} ,
{
test : /\.jsx?$/ ,
exclude : /node_modules/ ,
2023-11-09 18:02:57 +08:00
use : [
{
loader : "babel-loader" ,
options : {
presets : [ [ "@babel/preset-env" , "@babel/preset-react" ] ] ,
} ,
2023-05-05 23:08:48 +08:00
} ,
2023-11-09 18:02:57 +08:00
] ,
2023-05-04 16:09:19 +08:00
} ,
{
test : /\.css$/i ,
use : [
{
2023-11-09 18:02:57 +08:00
loader : "style-loader" ,
2023-05-04 16:09:19 +08:00
} ,
{
2023-11-09 18:02:57 +08:00
loader : "css-loader" ,
2023-05-04 16:09:19 +08:00
options : {
modules : {
2023-11-09 18:02:57 +08:00
localIdentName : "[name]__[local]___[hash:base64:5]" ,
} ,
} ,
} ,
2023-05-04 16:09:19 +08:00
] ,
2023-11-09 18:02:57 +08:00
include : /views/ ,
2023-05-04 16:09:19 +08:00
} ,
{
test : /\.json$/i ,
2023-11-09 18:02:57 +08:00
use : "json-loader" ,
type : "asset/source" ,
2023-05-04 16:09:19 +08:00
} ,
{
2023-05-18 13:58:17 +08:00
test : /\.(png|jpg|jpeg|gif|svg)$/ , // 匹配文件类型
2023-05-04 16:09:19 +08:00
use : [
{
2023-11-09 18:02:57 +08:00
loader : "file-loader" , // 使用file-loader
2023-05-04 16:09:19 +08:00
options : {
2023-11-09 18:02:57 +08:00
name : "[name].[ext]" , // 输出文件的名称和扩展名
outputPath : "assets/" , // 输出文件的路径
2023-05-04 16:09:19 +08:00
} ,
} ,
] ,
2023-11-09 18:02:57 +08:00
} ,
] ,
2023-04-14 08:05:41 +08:00
} ,
2023-11-09 18:02:57 +08:00
devtool : "source-map" ,
2023-04-14 08:05:41 +08:00
infrastructureLogging : {
2023-05-05 23:08:48 +08:00
level : "log" ,
2023-04-14 08:05:41 +08:00
} ,
2023-05-04 16:09:19 +08:00
plugins : [
// generate an HTML file that includes the extension's JavaScript file
new HtmlWebpackPlugin ( {
2023-11-09 18:02:57 +08:00
template : path . resolve ( _ _dirname , "src" , "index.html" ) ,
filename : "index.html" ,
chunks : [ "index" ] ,
2023-05-04 16:09:19 +08:00
} ) ,
2023-05-18 13:58:17 +08:00
new HtmlWebpackPlugin ( {
2023-11-09 18:02:57 +08:00
template : path . resolve ( _ _dirname , "src" , "welcome.html" ) ,
filename : "welcome.html" ,
chunks : [ "welcome" ] ,
2023-05-18 13:58:17 +08:00
} ) ,
2023-11-23 14:42:15 +08:00
new DefinePlugin ( {
"process.env.platform" : JSON . stringify ( "vscode" ) ,
} ) ,
2023-11-09 18:02:57 +08:00
] ,
2023-04-14 08:05:41 +08:00
} ;
2023-05-04 16:09:19 +08:00
2023-12-13 15:06:05 +08:00
module . exports = extensionConfig ;