-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
88 lines (83 loc) · 1.89 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
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
let HtmlWebpackPlugin = require('html-webpack-plugin');
console.log(chalk.green('> 复制配置及资源文件'));
if (!fs.existsSync('./build')) fs.mkdirSync('./build');
fs.writeFileSync('./build/manifest.json', fs.readFileSync('./src/manifest.json'));
fs.writeFileSync('./build/monitor-icon.png', fs.readFileSync('./src/monitor-icon.png'));
console.log(chalk.green('> 复制文件完成'));
console.log(chalk.green('> 开始打包'));
const pageDirs = fs.readdirSync('./src/pages');
const entry = () => {
let _entry = {};
fs.readdirSync('./src').map(file => {
if (file.includes('.ts')) {
let name = file.split('.')[0];
_entry[name] = `./src/${name}.ts`;
}
});
pageDirs.forEach(dir => {
_entry[dir] = `./src/pages/${dir}/index.tsx`;
});
return _entry;
}
const htmlWebpackPlugins = (() => {
let arr = [];
pageDirs.forEach(item => {
arr.push(new HtmlWebpackPlugin({
filename: `${item}.html`,
template: `./src/pages/${item}/index.html`,
chunks: [item],
}))
})
return arr;
})();
module.exports = {
mode: 'development',
entry,
output: {
filename: "[name].js",
path: path.join(__dirname, 'build')
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
},
{
test: /.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
},
]
},
plugins: [
...htmlWebpackPlugins
],
resolve: {
modules: [
'node_modules'
],
extensions: ['.js', '.ts', '.tsx'],
alias: {
'@': './src',
react: 'react/cjs/react.production.min.js'
}
},
devServer: {
port: 9000
}
}