eslint js 文件并启用缓存 --cache (#7330)

* chore: lint js file and use cache to speed up

* chore: autofix and format code
This commit is contained in:
Percy Ma 2023-02-11 23:04:14 +08:00 committed by GitHub
parent 9680294d39
commit ab15c09e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 207 additions and 207 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
*.jar *.jar
*.syso *.syso
.DS_Store .DS_Store
.eslintcache
app/node_modules app/node_modules
app/stage/build app/stage/build
app/build app/build

View File

@ -3,4 +3,6 @@ dist
electron electron
node_modules node_modules
public public
*.js src/asset/pdf
stage
appearance

View File

@ -1,23 +1,24 @@
module.exports = { module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', env: { node: true, browser: true, es6: true },
parser: "@typescript-eslint/parser",
plugins: [ plugins: [
'@typescript-eslint', "@typescript-eslint",
], ],
extends: [ extends: [
'eslint:recommended', "eslint:recommended",
'plugin:@typescript-eslint/recommended', "plugin:@typescript-eslint/recommended",
], ],
rules: { rules: {
semi: [2, 'always'], semi: [2, "always"],
quotes: [2, 'double', {'avoidEscape': true}], quotes: [2, "double", {"avoidEscape": true}],
'no-prototype-builtins': 'off', "no-prototype-builtins": "off",
'no-useless-escape': 'off', "no-useless-escape": "off",
'no-irregular-whitespace': 'off', "no-irregular-whitespace": "off",
'@typescript-eslint/ban-ts-comment': 'off', "@typescript-eslint/ban-ts-comment": "off",
'@typescript-eslint/no-var-requires': 'off', "@typescript-eslint/no-var-requires": "off",
'@typescript-eslint/explicit-function-return-type': 'off', "@typescript-eslint/explicit-function-return-type": "off",
'@typescript-eslint/explicit-module-boundary-types': 'off', "@typescript-eslint/explicit-module-boundary-types": "off",
'@typescript-eslint/no-explicit-any': 'off', "@typescript-eslint/no-explicit-any": "off",
}, },
} };

View File

@ -6,7 +6,7 @@
"main": "./electron/main.js", "main": "./electron/main.js",
"packageManager": "pnpm@7.26.1", "packageManager": "pnpm@7.26.1",
"scripts": { "scripts": {
"lint": "eslint . --fix --ext .ts", "lint": "eslint . --fix --cache",
"dev": "webpack --mode development", "dev": "webpack --mode development",
"dev:mobile": "webpack --mode development --config webpack.mobile.js", "dev:mobile": "webpack --mode development --config webpack.mobile.js",
"dev:desktop": "webpack --mode development --config webpack.desktop.js", "dev:desktop": "webpack --mode development --config webpack.desktop.js",

View File

@ -410,7 +410,7 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFil
/// #if MOBILE /// #if MOBILE
emojiElement = document.querySelector(`#sidebar [data-type="sidebar-file"] [data-node-id="${id}"] .b3-list-item__icon`); emojiElement = document.querySelector(`#sidebar [data-type="sidebar-file"] [data-node-id="${id}"] .b3-list-item__icon`);
/// #else /// #else
const dockFile = getDockByType("file") const dockFile = getDockByType("file");
if (dockFile) { if (dockFile) {
const files = dockFile.data.file as Files; const files = dockFile.data.file as Files;
if (icon === "iconFile") { if (icon === "iconFile") {

View File

@ -1478,7 +1478,7 @@ export class WYSIWYG {
let shiftStartElement: HTMLElement; let shiftStartElement: HTMLElement;
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => { this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
hideElements(["hint", "util"], protyle); hideElements(["hint", "util"], protyle);
const ctrlIsPressed = event.metaKey || event.ctrlKey const ctrlIsPressed = event.metaKey || event.ctrlKey;
/// #if !MOBILE /// #if !MOBILE
const backlinkBreadcrumbItemElement = hasClosestByClassName(event.target, "protyle-breadcrumb__item"); const backlinkBreadcrumbItemElement = hasClosestByClassName(event.target, "protyle-breadcrumb__item");
if (backlinkBreadcrumbItemElement) { if (backlinkBreadcrumbItemElement) {

View File

@ -903,19 +903,19 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
} }
(element.querySelector("#searchInput") as HTMLInputElement).value = item.k; (element.querySelector("#searchInput") as HTMLInputElement).value = item.k;
(element.querySelector("#replaceInput") as HTMLInputElement).value = item.r; (element.querySelector("#replaceInput") as HTMLInputElement).value = item.r;
let methodTip = window.siyuan.languages.searchMethod + " " let methodTip = window.siyuan.languages.searchMethod + " ";
switch (item.method) { switch (item.method) {
case 0: case 0:
methodTip += window.siyuan.languages.keyword; methodTip += window.siyuan.languages.keyword;
break; break;
case 1: case 1:
methodTip += window.siyuan.languages.querySyntax methodTip += window.siyuan.languages.querySyntax;
break; break;
case 2: case 2:
methodTip += "SQL" methodTip += "SQL";
break; break;
case 3: case 3:
methodTip += window.siyuan.languages.regex methodTip += window.siyuan.languages.regex;
break; break;
} }
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", methodTip); element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", methodTip);

View File

@ -1,26 +1,25 @@
const path = require('path') const path = require("path");
const webpack = require('webpack') 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( // const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
'webpack-bundle-analyzer').BundleAnalyzerPlugin const TerserPlugin = require("terser-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin')
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,
@ -37,23 +36,23 @@ module.exports = (env, argv) => {
}, },
resolve: { resolve: {
fallback: { fallback: {
'path': require.resolve('path-browserify'), "path": require.resolve("path-browserify"),
}, },
extensions: ['.ts', '.js', '.scss'], extensions: [".ts", ".js", ".scss"],
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.ts(x?)$/, test: /\.ts(x?)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, "src")],
use: [ use: [
{ {
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
loader: 'ifdef-loader', loader: "ifdef-loader",
options: { options: {
'ifdef-verbose': false, "ifdef-verbose": false,
BROWSER: true, BROWSER: true,
MOBILE: true, MOBILE: true,
}, },
@ -66,12 +65,12 @@ module.exports = (env, argv) => {
// new BundleAnalyzerPlugin(), // new BundleAnalyzerPlugin(),
new CleanWebpackPlugin({ new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [ cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'stage/build/api')], path.join(__dirname, "stage/build/api")],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(argv.mode), NODE_ENV: JSON.stringify(argv.mode),
SIYUAN_VERSION: JSON.stringify(pkg.version), SIYUAN_VERSION: JSON.stringify(pkg.version),
}), }),
], ],
} };
} };

View File

@ -1,28 +1,28 @@
const path = require('path') const path = require("path");
const webpack = require('webpack') const webpack = require("webpack");
const pkg = require('./package.json') const pkg = require("./package.json");
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin') const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin') const TerserPlugin = require("terser-webpack-plugin");
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,
target: 'electron-renderer', target: "electron-renderer",
output: { output: {
publicPath: '', publicPath: "",
filename: '[name].[chunkhash].js', filename: "[name].[chunkhash].js",
path: path.resolve(__dirname, 'stage/build/app'), path: path.resolve(__dirname, "stage/build/app"),
}, },
entry: { entry: {
'main': './src/index.ts', "main": "./src/index.ts",
'window': './src/window/index.ts', "window": "./src/window/index.ts",
}, },
resolve: { resolve: {
extensions: ['.ts', '.js', '.tpl', '.scss', '.png', '.svg'], extensions: [".ts", ".js", ".tpl", ".scss", ".png", ".svg"],
}, },
optimization: { optimization: {
minimize: true, minimize: true,
@ -42,22 +42,22 @@ module.exports = (env, argv) => {
{ {
test: /\.tpl/, test: /\.tpl/,
include: [ include: [
path.resolve(__dirname, 'src/assets/template/app/index.tpl'), path.resolve(__dirname, "src/assets/template/app/index.tpl"),
path.resolve(__dirname, 'src/assets/template/app/window.tpl')], path.resolve(__dirname, "src/assets/template/app/window.tpl")],
loader: 'html-loader', loader: "html-loader",
options: { options: {
sources: false, sources: false,
}, },
}, },
{ {
test: /\.ts(x?)$/, test: /\.ts(x?)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, "src")],
use: [ use: [
{ {
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
loader: 'ifdef-loader', options: { loader: "ifdef-loader", options: {
BROWSER: false, BROWSER: false,
MOBILE: false, MOBILE: false,
}, },
@ -67,33 +67,33 @@ module.exports = (env, argv) => {
{ {
test: /\.scss$/, test: /\.scss$/,
include: [ include: [
path.resolve(__dirname, 'src/assets/scss'), path.resolve(__dirname, "src/assets/scss"),
], ],
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader', // translates CSS into CommonJS loader: "css-loader", // translates CSS into CommonJS
}, },
{ {
loader: 'sass-loader', // compiles Sass to CSS loader: "sass-loader", // compiles Sass to CSS
}, },
], ],
}, },
{ {
test: /\.woff$/, test: /\.woff$/,
type: 'asset/resource', type: "asset/resource",
generator: { generator: {
filename: '../fonts/JetBrainsMono-Regular.woff', filename: "../fonts/JetBrainsMono-Regular.woff",
}, },
}, },
{ {
test: /\.(png|svg)$/, test: /\.(png|svg)$/,
use: [ use: [
{ {
loader: 'file-loader', loader: "file-loader",
options: { options: {
name: '[name].[ext]', name: "[name].[ext]",
outputPath: '../../', outputPath: "../../",
}, },
}, },
], ],
@ -104,27 +104,27 @@ module.exports = (env, argv) => {
new CleanWebpackPlugin({ new CleanWebpackPlugin({
cleanStaleWebpackAssets: false, cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [ cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'stage/build/app')], path.join(__dirname, "stage/build/app")],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
SIYUAN_VERSION: JSON.stringify(pkg.version), SIYUAN_VERSION: JSON.stringify(pkg.version),
NODE_ENV: JSON.stringify(argv.mode), NODE_ENV: JSON.stringify(argv.mode),
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'base.[contenthash].css', filename: "base.[contenthash].css",
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
inject: 'head', inject: "head",
chunks: ['main'], chunks: ["main"],
filename: 'index.html', filename: "index.html",
template: 'src/assets/template/app/index.tpl', template: "src/assets/template/app/index.tpl",
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
inject: 'head', inject: "head",
chunks: ['window'], chunks: ["window"],
filename: 'window.html', filename: "window.html",
template: 'src/assets/template/app/window.tpl', template: "src/assets/template/app/window.tpl",
}), }),
], ],
} };
} };

View File

@ -1,25 +1,24 @@
const path = require('path') const path = require("path");
const webpack = require('webpack') const webpack = require("webpack");
const pkg = require('./package.json') const pkg = require("./package.json");
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin') const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const BundleAnalyzerPlugin = require( // const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
'webpack-bundle-analyzer').BundleAnalyzerPlugin const TerserPlugin = require("terser-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin')
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].[chunkhash].js', filename: "[name].[chunkhash].js",
path: path.resolve(__dirname, 'stage/build/desktop'), path: path.resolve(__dirname, "stage/build/desktop"),
}, },
entry: { entry: {
'main': './src/index.ts', "main": "./src/index.ts",
}, },
optimization: { optimization: {
minimize: true, minimize: true,
@ -36,31 +35,31 @@ module.exports = (env, argv) => {
}, },
resolve: { resolve: {
fallback: { fallback: {
'path': require.resolve('path-browserify'), "path": require.resolve("path-browserify"),
}, },
extensions: ['.ts', '.js', '.tpl', '.scss'], extensions: [".ts", ".js", ".tpl", ".scss"],
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.tpl/, test: /\.tpl/,
include: [ include: [
path.resolve(__dirname, 'src/assets/template/desktop/index.tpl')], path.resolve(__dirname, "src/assets/template/desktop/index.tpl")],
loader: 'html-loader', loader: "html-loader",
options: { options: {
sources: false, sources: false,
}, },
}, },
{ {
test: /\.js$/, test: /\.js$/,
include: [path.resolve(__dirname, 'src/asset/pdf')], include: [path.resolve(__dirname, "src/asset/pdf")],
use: { use: {
loader: 'babel-loader', loader: "babel-loader",
options: { options: {
presets: ['@babel/preset-env'], presets: ["@babel/preset-env"],
plugins: [ plugins: [
[ [
'@babel/plugin-transform-runtime', "@babel/plugin-transform-runtime",
{ {
helpers: false, helpers: false,
regenerator: true, regenerator: true,
@ -72,15 +71,15 @@ module.exports = (env, argv) => {
}, },
{ {
test: /\.ts(x?)$/, test: /\.ts(x?)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, "src")],
use: [ use: [
{ {
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
loader: 'ifdef-loader', loader: "ifdef-loader",
options: { options: {
'ifdef-verbose': false, "ifdef-verbose": false,
BROWSER: true, BROWSER: true,
MOBILE: false, MOBILE: false,
}, },
@ -90,33 +89,33 @@ module.exports = (env, argv) => {
{ {
test: /\.scss$/, test: /\.scss$/,
include: [ include: [
path.resolve(__dirname, 'src/assets/scss'), path.resolve(__dirname, "src/assets/scss"),
], ],
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader', // translates CSS into CommonJS loader: "css-loader", // translates CSS into CommonJS
}, },
{ {
loader: 'sass-loader', // compiles Sass to CSS loader: "sass-loader", // compiles Sass to CSS
}, },
], ],
}, },
{ {
test: /\.woff$/, test: /\.woff$/,
type: 'asset/resource', type: "asset/resource",
generator: { generator: {
filename: '../fonts/JetBrainsMono-Regular.woff', filename: "../fonts/JetBrainsMono-Regular.woff",
}, },
}, },
{ {
test: /\.(png|svg)$/, test: /\.(png|svg)$/,
use: [ use: [
{ {
loader: 'file-loader', loader: "file-loader",
options: { options: {
name: '[name].[ext]', name: "[name].[ext]",
outputPath: '../../', outputPath: "../../",
}, },
}, },
], ],
@ -128,21 +127,21 @@ module.exports = (env, argv) => {
new CleanWebpackPlugin({ new CleanWebpackPlugin({
cleanStaleWebpackAssets: false, cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [ cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'stage/build/desktop')], path.join(__dirname, "stage/build/desktop")],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
SIYUAN_VERSION: JSON.stringify(pkg.version), SIYUAN_VERSION: JSON.stringify(pkg.version),
NODE_ENV: JSON.stringify(argv.mode), NODE_ENV: JSON.stringify(argv.mode),
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'base.[contenthash].css', filename: "base.[contenthash].css",
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
inject: 'head', inject: "head",
chunks: ['main'], chunks: ["main"],
filename: 'index.html', filename: "index.html",
template: 'src/assets/template/desktop/index.tpl', template: "src/assets/template/desktop/index.tpl",
}), }),
], ],
} };
} };

View File

@ -1,27 +1,26 @@
const path = require('path') const path = require("path");
const webpack = require('webpack') const webpack = require("webpack");
const pkg = require('./package.json') const pkg = require("./package.json");
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin') const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const BundleAnalyzerPlugin = require( // const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
'webpack-bundle-analyzer').BundleAnalyzerPlugin const TerserPlugin = require("terser-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin')
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/export'), path: path.resolve(__dirname, "stage/build/export"),
libraryTarget: 'umd', libraryTarget: "umd",
library: 'Protyle', library: "Protyle",
libraryExport: 'default', libraryExport: "default",
}, },
entry: { entry: {
'protyle-method': './src/protyle/method.ts', "protyle-method": "./src/protyle/method.ts",
}, },
optimization: { optimization: {
minimize: true, minimize: true,
@ -38,23 +37,23 @@ module.exports = (env, argv) => {
}, },
resolve: { resolve: {
fallback: { fallback: {
'path': require.resolve('path-browserify'), "path": require.resolve("path-browserify"),
}, },
extensions: ['.ts', '.js', '.scss'], extensions: [".ts", ".js", ".scss"],
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.ts(x?)$/, test: /\.ts(x?)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, "src")],
use: [ use: [
{ {
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
loader: 'ifdef-loader', loader: "ifdef-loader",
options: { options: {
'ifdef-verbose': false, "ifdef-verbose": false,
BROWSER: true, BROWSER: true,
MOBILE: true, MOBILE: true,
}, },
@ -64,23 +63,23 @@ module.exports = (env, argv) => {
{ {
test: /\.scss$/, test: /\.scss$/,
include: [ include: [
path.resolve(__dirname, 'src/assets/scss'), path.resolve(__dirname, "src/assets/scss"),
], ],
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader', // translates CSS into CommonJS loader: "css-loader", // translates CSS into CommonJS
}, },
{ {
loader: 'sass-loader', // compiles Sass to CSS loader: "sass-loader", // compiles Sass to CSS
}, },
], ],
}, },
{ {
test: /\.woff$/, test: /\.woff$/,
type: 'asset/resource', type: "asset/resource",
generator: { generator: {
filename: '../fonts/JetBrainsMono-Regular.woff', filename: "../fonts/JetBrainsMono-Regular.woff",
}, },
}, },
], ],
@ -89,15 +88,15 @@ module.exports = (env, argv) => {
// new BundleAnalyzerPlugin(), // new BundleAnalyzerPlugin(),
new CleanWebpackPlugin({ new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [ cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'stage/build/export')], path.join(__dirname, "stage/build/export")],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(argv.mode), NODE_ENV: JSON.stringify(argv.mode),
SIYUAN_VERSION: JSON.stringify(pkg.version), SIYUAN_VERSION: JSON.stringify(pkg.version),
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'base.css', filename: "base.css",
}), }),
], ],
} };
} };

View File

@ -1,25 +1,24 @@
const path = require('path') const path = require("path");
const webpack = require('webpack') const webpack = require("webpack");
const pkg = require('./package.json') const pkg = require("./package.json");
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin') const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const BundleAnalyzerPlugin = require( // const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
'webpack-bundle-analyzer').BundleAnalyzerPlugin const TerserPlugin = require("terser-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin')
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].[chunkhash].js', filename: "[name].[chunkhash].js",
path: path.resolve(__dirname, 'stage/build/mobile'), path: path.resolve(__dirname, "stage/build/mobile"),
}, },
entry: { entry: {
'main': './src/mobile/index.ts', "main": "./src/mobile/index.ts",
}, },
optimization: { optimization: {
minimize: true, minimize: true,
@ -36,32 +35,32 @@ module.exports = (env, argv) => {
}, },
resolve: { resolve: {
fallback: { fallback: {
'path': require.resolve('path-browserify'), "path": require.resolve("path-browserify"),
}, },
extensions: ['.ts', '.js', '.tpl', '.scss'], extensions: [".ts", ".js", ".tpl", ".scss"],
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.tpl/, test: /\.tpl/,
include: [ include: [
path.resolve(__dirname, 'src/assets/template/mobile/index.tpl')], path.resolve(__dirname, "src/assets/template/mobile/index.tpl")],
loader: 'html-loader', loader: "html-loader",
options: { options: {
sources: false, sources: false,
}, },
}, },
{ {
test: /\.ts(x?)$/, test: /\.ts(x?)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, "src")],
use: [ use: [
{ {
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
loader: 'ifdef-loader', loader: "ifdef-loader",
options: { options: {
'ifdef-verbose': false, "ifdef-verbose": false,
BROWSER: true, BROWSER: true,
MOBILE: true, MOBILE: true,
}, },
@ -71,33 +70,33 @@ module.exports = (env, argv) => {
{ {
test: /\.scss$/, test: /\.scss$/,
include: [ include: [
path.resolve(__dirname, 'src/assets/scss'), path.resolve(__dirname, "src/assets/scss"),
], ],
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader', // translates CSS into CommonJS loader: "css-loader", // translates CSS into CommonJS
}, },
{ {
loader: 'sass-loader', // compiles Sass to CSS loader: "sass-loader", // compiles Sass to CSS
}, },
], ],
}, },
{ {
test: /\.woff$/, test: /\.woff$/,
type: 'asset/resource', type: "asset/resource",
generator: { generator: {
filename: '../fonts/JetBrainsMono-Regular.woff', filename: "../fonts/JetBrainsMono-Regular.woff",
}, },
}, },
{ {
test: /\.(png|svg)$/, test: /\.(png|svg)$/,
use: [ use: [
{ {
loader: 'file-loader', loader: "file-loader",
options: { options: {
name: '[name].[ext]', name: "[name].[ext]",
outputPath: '../../', outputPath: "../../",
}, },
}, },
], ],
@ -109,21 +108,21 @@ module.exports = (env, argv) => {
new CleanWebpackPlugin({ new CleanWebpackPlugin({
cleanStaleWebpackAssets: false, cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [ cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'stage/build/mobile')], path.join(__dirname, "stage/build/mobile")],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
SIYUAN_VERSION: JSON.stringify(pkg.version), SIYUAN_VERSION: JSON.stringify(pkg.version),
NODE_ENV: JSON.stringify(argv.mode), NODE_ENV: JSON.stringify(argv.mode),
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'base.[contenthash].css', filename: "base.[contenthash].css",
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
inject: 'head', inject: "head",
chunks: ['main'], chunks: ["main"],
filename: 'index.html', filename: "index.html",
template: 'src/assets/template/mobile/index.tpl', template: "src/assets/template/mobile/index.tpl",
}), }),
], ],
} };
} };