-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
117 lines (113 loc) · 3.19 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
var { resolve } = require('path')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var TerserPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssassetsWebpackPlugin = require("optimize-css-assets-webpack-plugin")
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const Webpack = require("webpack")
module.exports = (env, argv)=>{
return {
entry: {
'dp-video': './src/index.js',
'dp-video.min': './src/index.js',
},
output: {
filename: 'js/[name].js',
library: 'dpVideo', // 指定包名
libraryExport: 'default', // _entry_return_.default;
libraryTarget: 'var',
path: resolve(__dirname, 'dist'),
publicPath: "/dist"
},
module: {
rules: [
{
// 匹配那些文件
test: /\.css$/,
// 使用哪些loader处理
use: [
argv.mode == "production" ? MiniCssExtractPlugin.loader : 'style-loader',
// 执行顺序,从右到左,从下到上,依次执行
// 'style-loader',
'css-loader',
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: () => [
require("postcss-preset-env")()
]
}
}
],
},
{
test: /\.tsx?$/,
use:['babel-loader',"ts-loader"],
// use:["ts-loader"],
exclude: [resolve(__dirname, "node_modules")]
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
// loader: 'url-loader?name=images/[name].[ext]',
loader: 'url-loader',
options: {
limit: 10,
name:'font/[name].[ext]'
}
},
{
test: /\.(mp4)(\?.*)?$/,
loader: 'url-loader',
options: {
name:'video/[name].[ext]',
limit:10
}
}
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new MiniCssExtractPlugin({
filename: '/css/style.css', // 从 .js 文件中提取出来的 .css 文件的名称
}),
new OptimizeCssassetsWebpackPlugin(),
new BundleAnalyzerPlugin(),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /min/,
}),
],
},
mode: argv.mode == "production" ? "production" : 'development',
resolve: {
extensions: [".ts",".js",".json"]
},
//
devServer: argv.mode == "production" ? {} :{
// 端口号
port: 7000,
// 项目构建后的路径
contentBase: resolve(__dirname, 'dist'),
// 启用g-zip压缩
compress: true,
// 自动打开浏览器
open: true,
// 开启HMR功能
// 当修改了webpack配置,新配置要想生效,必须重启webpack配置
hot: true,
},
}
}