-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.lib.config.js
111 lines (99 loc) · 2.69 KB
/
webpack.lib.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
var path = require("path");
var webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const fs = require('fs');
const package = JSON.parse(fs.readFileSync('./package.json'));
module.exports = {
// 根据不同的执行环境配置不同的入口
entry: "./src/components/index.js",
output:{
clean: true,
path: path.resolve(__dirname, "./lib"),
// publicPath: "/lib/",
filename: "mo-quarter-picker.min.js",
// 输出一个库
library: {
// 指定的就是你使用require时的模块名
name: "MoQuarterPicker",
// CMD只能在 Node 环境执行,AMD 只能在浏览器端执行,UMD 同时支持两种执行环境
type: "umd",
// 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define
umdNamedDefine: true
},
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"]
},
{
test: /\.vue$/,
loader: "vue-loader"
// options: {
// loaders: {}
// // other vue-loader options go here
// }
},
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ['@babel/preset-env']
}
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: "file-loader",
options: {
name: "[name].[ext]?[hash]"
}
}
]
},
plugins: [
// new HtmlWebpackPlugin({
// template: "./public/index.html"
// }),
// 请确保引入这个插件!
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: "mo-quarter-picker.min.css",
}),
// 版本信息
new webpack.BannerPlugin({
banner: `${package.name} \nV${package.version}`,
})
],
// 模式
mode: "production",
externals: {
moment: "moment",
Vue: "vue",
ElementUI: "element-ui"
},
devtool: false,
// devtool: "#eval-source-map"
optimization: {
// 开发环境下启用 CSS 优化
minimize: true,
minimizer: [
// 使用 cssnano 优化和压缩 CSS
new CssMinimizerPlugin(),
// 使用 terser 优化和压缩 JS
new TerserPlugin({
// 不将注释提取到单独的文件中
extractComments: false
})
]
}
};