-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
151 lines (146 loc) · 4.42 KB
/
Copy pathwebpack.dev.js
File metadata and controls
151 lines (146 loc) · 4.42 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require("path");
const Webpack = require("webpack");
// creates index.html file by a template index.ejs
const HtmlWebpackPlugin = require("html-webpack-plugin");
// cleans dist folder
const CleanWebpackPlugin = require("clean-webpack-plugin");
// copies the assets folder into dist folder
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const distFolder = "./dist";
const sections = [
"index",
"helloworld",
"primitives",
"linght-shadow-material",
"load-gltf",
"interactive",
"gpu-picking",
"model-control",
"animation-basic",
"animation-tween",
"animation-model",
"shader",
"postprocess",
];
let entryPoints = {};
let copyhtml = [];
for (let i = 0; i < sections.length; i++) {
var chunk = sections[i];
entryPoints[chunk] = `./src/scripts/${chunk}.js`;
copyhtml.push(
new HtmlWebpackPlugin({
title: "threejs知多少-" + chunk,
filename: `${chunk}.html`,
template: `src/html/${chunk}.html`,
chunks: ["vendors", chunk],
minify: {
removeRedundantAttributes: true, // 删除多余的属性
collapseWhitespace: true, // 折叠空白区域
removeAttributeQuotes: true, // 移除属性的引号
removeComments: true, // 移除注释
collapseBooleanAttributes: true, // 省略只有 boolean 值的属性值 例如:readonly checked
},
})
);
}
module.exports = {
mode: "development",
entry: entryPoints,
output: {
filename: "js/[name].[hash:5].js",
path: path.resolve(__dirname, distFolder),
},
devtool: "inline-source-map",
plugins: [
require("autoprefixer"),
new MiniCssExtractPlugin({
filename: "css/.[hash:5].css",
options: {
publicPath: "../../",
},
}),
new Webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(
distFolder
//{ root: path.resolve(__dirname, '../')}
),
new CopyWebpackPlugin([
{
from: "src/static",
to: "assets",
},
]),
...copyhtml,
],
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "../",
},
},
"css-loader?importLoaders=1",
"postcss-loader",
],
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "../",
},
},
"css-loader?importLoaders=1",
"postcss-loader",
"less-loader",
],
},
{
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
use: "file-loader",
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: "file-loader",
options: {
esModule: false,
name: "[name]_[hash:8].[ext]",
// publicPath: "assets/images",
outputPath: "./images", //定义输出的图片文件夹
},
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".css", ".less"],
},
devServer: {
contentBase: distFolder, //网站的根目录为 根目录/dist,如果配置不对,会报Cannot GET /错误
port: 9000, //端口改为9000
open: true, // 自动打开浏览器,适合懒人
hot: true,
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all",
},
},
},
},
};