forked from Xuans/AIM_Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
85 lines (82 loc) · 2.09 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
/**
* 方案一
* 生成的文件为
* -dist
* - img
* - index
* - index.js
* - index.css
* - index.html
* - page1
* - index.js
* - index.css
* - index.html
* - page2
* - index.js
* - index.css
* - index.html
*/
const path = require("path");
const glob = require("glob");
const fs = require("fs");
const config = {
entry: "main.js",
html: "index.html",
pattern: [
//大连 POC
"src/pages/dlPoc/*"
]
};
const genPages = () => {
const pages = {};
const pageEntries = config.pattern.map(e => {
const matches = glob.sync(path.resolve(__dirname, e));
return matches.filter(match => fs.existsSync(`${match}/${config.entry}`));
});
Array.prototype.concat.apply([], pageEntries).forEach(dir => {
const filename = dir.split('pages/')[1];
const pathName = 'src' + dir.split('src')[1]
pages[filename] = {
entry: `${pathName}/${config.entry}`,
template: `${pathName}/${config.html}`,
filename: `pages/${filename}/${config.html}`,
};
});
return pages;
};
const pages = genPages();
module.exports = {
productionSourceMap: false,
pages,
chainWebpack: config => {
Object.keys(pages).forEach(entryName => {
config.plugins.delete(`prefetch-${entryName}`);
});
if (process.env.NODE_ENV === "production") {
config.plugin("extract-css").tap(() => [
// {
// filename: "[name]/css/[name].[contenthash:8].css",
// chunkFilename: "[name]/css/[name].[contenthash:8].css"
// }
{
filename: "pages/[name]/style.css",
chunkFilename: "[name]/css/[name].css"
}
]);
}
},
configureWebpack: config => {
if (process.env.NODE_ENV === "production") {
config.output = {
libraryTarget:'umd',
//filenameHashing:false,
path: path.join(__dirname, "./dist"),
// filename: "[name]/js/[name].[contenthash:8].js",
filename: "pages/[name]/script.js",
publicPath: "/",
// chunkFilename: "[name]/js/[name].[contenthash:8].js"
chunkFilename: "[name]/js/[name].js"
};
}
}
};