Vanessa 2023-03-24 20:28:31 +08:00
parent b0b5d209ab
commit 7a6ea5f221
4 changed files with 69 additions and 63 deletions

View file

@ -3,7 +3,7 @@
"outDir": "./dist/", "outDir": "./dist/",
"noImplicitAny": true, "noImplicitAny": true,
"module": "commonjs", "module": "commonjs",
"target": "es2021", "target": "es6",
"typeRoots": [ "typeRoots": [
"./node_modules/@types" "./node_modules/@types"
], ],

View file

@ -3,67 +3,70 @@ const webpack = require("webpack");
const pkg = require("./package.json"); const pkg = require("./package.json");
const {CleanWebpackPlugin} = require("clean-webpack-plugin"); const {CleanWebpackPlugin} = require("clean-webpack-plugin");
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; // const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const { EsbuildPlugin } = require("esbuild-loader"); const {EsbuildPlugin} = require("esbuild-loader");
module.exports = (env, argv) => { module.exports = (env, argv) => {
return { return {
mode: argv.mode || "development", mode: argv.mode || "development",
watch: argv.mode !== "production", watch: argv.mode !== "production",
devtool: argv.mode !== "production" ? "eval" : false, devtool: argv.mode !== "production" ? "eval" : false,
output: { output: {
publicPath: "", publicPath: "",
filename: "[name].js", filename: "[name].js",
path: path.resolve(__dirname, "stage/build/api"), path: path.resolve(__dirname, "stage/build/api"),
libraryTarget: "umd", libraryTarget: "umd",
library: "SiYuanAPI", library: "SiYuanAPI",
libraryExport: "default", libraryExport: "default",
}, },
entry: { entry: {
"api": "./src/api.ts", "api": "./src/api.ts",
}, },
optimization: { optimization: {
minimize: true, minimize: true,
minimizer: [ minimizer: [
new EsbuildPlugin(), new EsbuildPlugin({target: "es6"}),
], ],
}, },
resolve: { resolve: {
fallback: { fallback: {
"path": require.resolve("path-browserify"), "path": require.resolve("path-browserify"),
},
extensions: [".ts", ".js", ".scss"],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: "esbuild-loader",
}, },
{ extensions: [".ts", ".js", ".scss"],
loader: "ifdef-loader", },
options: { module: {
"ifdef-verbose": false, rules: [
BROWSER: true, {
MOBILE: true, test: /\.ts(x?)$/,
}, include: [path.resolve(__dirname, "src")],
}, use: [
], {
} loader: "esbuild-loader",
], options: {
}, target: "es6",
plugins: [ }
// new BundleAnalyzerPlugin(), },
new CleanWebpackPlugin({ {
cleanOnceBeforeBuildPatterns: [ loader: "ifdef-loader",
path.join(__dirname, "stage/build/api")], options: {
}), "ifdef-verbose": false,
new webpack.DefinePlugin({ BROWSER: true,
NODE_ENV: JSON.stringify(argv.mode), MOBILE: true,
SIYUAN_VERSION: JSON.stringify(pkg.version), },
}), },
], ],
}; }
],
},
plugins: [
// new BundleAnalyzerPlugin(),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
path.join(__dirname, "stage/build/api")],
}),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(argv.mode),
SIYUAN_VERSION: JSON.stringify(pkg.version),
}),
],
};
}; };

View file

@ -27,7 +27,7 @@ module.exports = (env, argv) => {
optimization: { optimization: {
minimize: true, minimize: true,
minimizer: [ minimizer: [
new EsbuildPlugin(), new EsbuildPlugin({target: "es2021"}),
], ],
}, },
module: { module: {

View file

@ -25,7 +25,7 @@ module.exports = (env, argv) => {
optimization: { optimization: {
minimize: true, minimize: true,
minimizer: [ minimizer: [
new EsbuildPlugin(), new EsbuildPlugin({target: "es6"}),
], ],
}, },
resolve: { resolve: {
@ -42,6 +42,9 @@ module.exports = (env, argv) => {
use: [ use: [
{ {
loader: "esbuild-loader", loader: "esbuild-loader",
options: {
target: "es6",
}
}, },
{ {
loader: "ifdef-loader", loader: "ifdef-loader",