DeepCodeGeniusWeb-vscode/webpack.config.js

172 lines
4.4 KiB
JavaScript
Raw Normal View History

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-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-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"],
},
module: {
rules: [
{
test: /\.ts?$/,
exclude: /node_modules/,
use: [
{
2023-11-09 18:02:57 +08:00
loader: "babel-loader",
options: {
presets: [
2023-11-09 18:02:57 +08:00
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
{
2023-11-09 18:02:57 +08:00
loader: "ts-loader",
},
],
},
2023-11-09 18:02:57 +08:00
],
},
2023-11-09 18:02:57 +08:00
devtool: "nosources-source-map",
infrastructureLogging: {
level: "log", // enables logging required for problem matchers
},
2023-11-09 18:02:57 +08:00
plugins: [],
};
/** @type WebpackConfig */
const webviewConfig = {
2023-11-09 18:02:57 +08:00
name: "webview",
target: "web",
mode: "development",
2023-11-09 18:02:57 +08:00
entry: "./src/index.tsx",
output: {
2023-11-09 18:02:57 +08:00
path: path.resolve(__dirname, "dist"),
filename: "index.js",
publicPath: "/",
},
resolve: {
2023-11-09 18:02:57 +08:00
extensions: [".ts", ".tsx", ".js", ".json"],
alias: {
2023-11-09 18:02:57 +08:00
"@": path.resolve(__dirname, "src/"),
},
2023-04-14 08:05:41 +08:00
},
module: {
rules: [
{
test: /\.tsx?$/,
2023-04-14 08:05:41 +08:00
exclude: /node_modules/,
use: [
{
2023-11-09 18:02:57 +08:00
loader: "babel-loader",
options: {
presets: [
2023-11-09 18:02:57 +08:00
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
2023-04-14 08:05:41 +08:00
{
2023-11-09 18:02:57 +08:00
loader: "ts-loader",
},
],
},
{
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-11-09 18:02:57 +08:00
],
},
{
test: /\.css$/i,
use: [
{
2023-11-09 18:02:57 +08:00
loader: "style-loader",
},
{
2023-11-09 18:02:57 +08:00
loader: "css-loader",
options: {
modules: {
2023-11-09 18:02:57 +08:00
localIdentName: "[name]__[local]___[hash:base64:5]",
},
},
},
],
2023-11-09 18:02:57 +08:00
include: /views/,
},
{
test: /\.json$/i,
2023-11-09 18:02:57 +08:00
use: "json-loader",
type: "asset/source",
},
{
test: /\.(png|jpg|jpeg|gif|svg)$/, // 匹配文件类型
use: [
{
2023-11-09 18:02:57 +08:00
loader: "file-loader", // 使用file-loader
options: {
2023-11-09 18:02:57 +08:00
name: "[name].[ext]", // 输出文件的名称和扩展名
outputPath: "assets/", // 输出文件的路径
},
},
],
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: {
level: "log",
2023-04-14 08:05:41 +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"],
}),
new HtmlWebpackPlugin({
2023-11-09 18:02:57 +08:00
template: path.resolve(__dirname, "src", "welcome.html"),
filename: "welcome.html",
chunks: ["welcome"],
}),
2023-11-09 18:02:57 +08:00
],
2023-04-14 08:05:41 +08:00
};
module.exports = [extensionConfig, webviewConfig];