generated from siyuan-note/plugin-sample
-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
133 lines (130 loc) · 3.97 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
const {EsbuildPlugin} = require("esbuild-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
module.exports = (env, argv) => {
const isPro = argv.mode === "production";
const plugins = [
new MiniCssExtractPlugin({
filename: isPro ? "dist/index.css" : "index.css",
}),
new webpack.DefinePlugin({
'__VUE_OPTIONS_API__': true,
'__VUE_PROD_DEVTOOLS__':false
}),
new VueLoaderPlugin()
];
let entry = {
"index": "./src/index.ts",
};
if (isPro) {
entry = {
"dist/index": "./src/index.ts",
};
plugins.push(new webpack.BannerPlugin({
banner: () => {
return fs.readFileSync("LICENSE").toString();
},
}));
plugins.push(new CopyPlugin({
patterns: [
{from: "preview.png", to: "./dist/"},
{from: "icon.png", to: "./dist/"},
{from: "README*.md", to: "./dist/"},
{from: "plugin.json", to: "./dist/"},
{from: "src/i18n/", to: "./dist/i18n/"},
{from: "src/components/qqmail.png", to: "./dist/"},
],
}));
plugins.push(new ZipPlugin({
filename: "package.zip",
algorithm: "gzip",
include: [/dist/],
pathMapper: (assetPath) => {
return assetPath.replace("dist/", "");
},
}));
} else {
plugins.push(new CopyPlugin({
patterns: [
{from: "src/i18n/", to: "./i18n/"},
],
}));
}
return {
mode: argv.mode || "development",
watch: !isPro,
devtool: isPro ? false : "eval",
output: {
filename: "[name].js",
path: path.resolve(__dirname),
libraryTarget: "commonjs2",
library: {
type: "commonjs2",
},
},
externals: {
siyuan: "siyuan",
},
entry,
optimization: {
minimize: true,
minimizer: [
new EsbuildPlugin(),
],
},
resolve: {
extensions: [".ts", ".scss", ".js", ".json"],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: "esbuild-loader",
options: {
target: "es6",
}
},
],
},
{
test: /\.scss$/,
include: [path.resolve(__dirname, "src")],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader", // translates CSS into CommonJS
},
{
loader: "sass-loader", // compiles Sass to CSS
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/],
}
},
{
test: /\.(jpg|png|svg|ttf)$/,
loader: 'url-loader'
}
],
},
plugins,
};
};