-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathvue.config.js
87 lines (82 loc) · 1.85 KB
/
vue.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
const fs = require("fs");
const path = require("path");
function resolve(dir) {
return path.resolve(__dirname, dir);
}
const join = path.join;
function getEntries(path) {
let files = fs.readdirSync(resolve(path));
const entries = files.reduce((ret, item) => {
const itemPath = join(path, item)
const isDir = fs.statSync(itemPath).isDirectory();
if (isDir) {
ret[item] = resolve(join(itemPath, 'index.js'))
} else {
const [name] = item.split('.')
ret[name] = resolve(`${itemPath}`)
}
return ret
}, {})
return entries
}
//开发环境配置
const devConfig = {
pages: {
index: {
entry: "examples/main.js",
template: "public/index.html",
filename: "index.html"
}
},
chainWebpack: config => {
config.module
.rule("js")
.include.add("/packages")
.end()
.use("babel")
.loader("babel-loader")
.tap(options => {
return options;
});
}
};
//生成环境配置
const buildConfig = {
outputDir: "lib",
productionSourceMap: false,
css: {
sourceMap: true,
extract: {
filename: "style/[name].css"
}
},
configureWebpack: {
entry: {
...getEntries("packages")
},
output: {
filename: "[name].js",
libraryTarget: "commonjs2"
}
},
chainWebpack: config => {
config.module
.rule("js")
.include.add("/packages")
.end()
.use("babel")
.loader("babel-loader")
.tap(options => {
return options;
});
config.optimization.delete("splitChunks");
config.plugins.delete("copy");
config.plugins.delete("html");
config.plugins.delete("preload");
config.plugins.delete("prefetch");
config.plugins.delete("hmr");
config.entryPoints.delete("app");
}
};
module.exports =
process.env.NODE_ENV === "development" ? devConfig : buildConfig;