-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathwebpack.config.js
112 lines (110 loc) · 2.91 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
// 一个常见的`webpack`配置文件
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const copyWebpackPlugin = require("copy-webpack-plugin");
// const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const path = require("path");
const resolve = dir => path.resolve(__dirname, dir);
module.exports = {
entry: __dirname + "/src/app.ts", //已多次提及的唯一入口文件
output: {
path: __dirname + "/dist",
filename: "[name].[hash].js"
},
resolve: {
alias: {
"@/*": __dirname + "/*",
},
extensions: [".tsx", ".ts", ".js"]//解析类型
},
devtool: "inline-source-map", //'source-map',
devServer: {
contentBase: "./dist", //本地服务器所加载的页面所在的目录
historyApiFallback: true, //不跳转
inline: true,
port: 2021,
open: true,
hot: true
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
use: {
loader: "babel-loader"
},
exclude: /node_modules/
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.(gif|png|jpe?g|svg|tif|glb)$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path][name].[ext]",
outputPath: './assets/'
}
}
]
}, // 下面几行才是 html-loader 的配置内容
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: {
minimize: true
}
}
]
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
plugins: [
new copyWebpackPlugin([
{
from: __dirname + "/src/assets", //打包的静态资源目录地址
to: "./assets" //打包到dist下面的public
}
]),
// new TsconfigPathsPlugin({/* options: see below */ }),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: "DUI",
template: "./index.html",
filename: "index.html",
minify: {
collapseWhitespace: true
},
hash: true
}),
new webpack.BannerPlugin("版权所有,翻版必究"),
// new HtmlWebpackPlugin({
// template: __dirname + "/index.html" //new 一个这个插件的实例,并传入相关的参数
// }),
new webpack.optimize.OccurrenceOrderPlugin(),
// new webpack.optimize.minimize(),
new ExtractTextPlugin({
filename: "style.css",
disable: true
}),
// 这两行是新增的
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
]
};