This repository has been archived by the owner on Jul 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
63 lines (60 loc) · 1.82 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
const path = require("path");
const fs = require("fs");
const CONF = require('./kaci.config.js');
let files = {};
const JSpath = path.resolve(process.cwd(), "./src/js");
const JSignore = CONF.js.ignore;
getEntries(JSpath, JSignore);
module.exports = {
mode: "production",
entry: files,
output: {
filename: "[name]",
path: path.resolve(__dirname, CONF.path.build, "js")
},
mode: "production",
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader"
}
}
]
},
externals: {
jquery: "jQuery"
},
};
// 获取多页面的每个入口文件,用于配置中的entry
function getEntries(filePath, ignorePath) {
//根据文件路径读取文件,返回文件列表
let rootFiles = fs.readdirSync(filePath);
//排除ignore
let targetFiles = [];
rootFiles.forEach(function(filename) {
if (!ignorePath.includes(filename)) {
targetFiles.push(filename);
}
});
//遍历读取到的文件列表
targetFiles.forEach(function(filename) {
//获取当前文件的绝对路径
let filedir = path.join(filePath, filename);
//根据文件路径获取文件信息,返回一个fs.Stats对象
let fileStat = fs.statSync(filedir);
//判断文件状态
let isFile = fileStat.isFile(); //是文件
let isDir = fileStat.isDirectory(); //是文件夹
//如果是文件
if (isFile) {
files[filename] = filedir;
}
//如果是文件夹
if (isDir) {
getEntries(filedir, ignorePath); //递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
});
}