This repository was archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvue.config.js
More file actions
147 lines (141 loc) · 4.64 KB
/
Copy pathvue.config.js
File metadata and controls
147 lines (141 loc) · 4.64 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
const path = require("path");
const rimraf = require("rimraf");
const cordovaConfig = require("cordova-config");
const VueAutomaticImportPlugin = require("vue-automatic-import-loader/lib/plugin");
const { devServerConfig, pageConfig } = require("./src/config/index");
const isProduction = process.env.NODE_ENV === "production";
const isDevelopment = process.env.NODE_ENV === "development";
const host = getLocalIP(); //获取本机IP
const port = devServerConfig.port || 8000;
const indexPath = isProduction ? "index.html" : `http://${host}:${port}`;
//dev时删除dist目录防止dev模式wifi同步不必要的文件
isDevelopment &&
rimraf(path.resolve(__dirname, "./dist"), (err) => {
if (err) throw err;
});
module.exports = {
publicPath: isProduction ? "./" : "./",
filenameHashing: isProduction /** 开发环境关闭文件哈希值 */,
devServer: {
// 环境配置
host,
port,
hot: true, //false防止开发模式白屏(使用路由缓存时)
open: false, //编译完成后打开浏览器
proxy: {
/** 解决本地测试跨域问题 */
[`/${devServerConfig.apiRoot}`]: {
target: devServerConfig.proxyUrl,
pathRewrite: {
[`^/${devServerConfig.apiRoot}`]: "",
},
},
},
writeToDisk: (file) => {
return /config.xml$/.test(file);
// return /index.html$/.test(file) || /config.xml$/.test(file);
},
},
pages: {
index: {
// page 的入口
entry: "src/main.js",
// 模板来源
template: "public/index.html",
// 在 dist/index.html 的输出
filename: "index.html",
// 当使用 title 选项时,
// template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
title: pageConfig.title,
// 在这个页面中包含的块,默认情况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
chunks: ["chunk-vendors", "chunk-common", "index"],
},
},
transpileDependencies: [
// "vuetify",
// "lottie-player-vue",
// "vue-awesome-swiper",
// "vue-tippy",
"axios-apicloud-adapter",
"vue-screen",
], //指定需要编译的依赖
// chainWebpack: config => {},
configureWebpack: {
plugins: [
//组件自动按需导入
new VueAutomaticImportPlugin({
match(originalTag, { kebabTag, camelTag, path, component }) {
if (kebabTag.startsWith("via-")) {
return [
camelTag,
`import ${camelTag} from '@/components/${camelTag}/index.vue';`,
];
}
if (kebabTag.startsWith("van-")) {
const componentName = kebabTag.slice(4);
return [
camelTag,
`
import ${camelTag} from 'vant/lib/${componentName}';
import 'vant/lib/${componentName}/style';
`,
];
}
/**
* originalTag - the tag as it was originally used in the template
* kebabTag - the tag normalised to kebab-case
* camelTag - the tag normalised to PascalCase
* path - a relative path to the current .vue file
* component - a parsed representation of the current component
*/
// console.log('originalTag:', originalTag);
// console.log('kebabTag:', kebabTag);
// console.log('camelTag:', camelTag);
// console.log('path:', path);
// console.log('component:', component);
},
}),
{
apply: (compiler) => {
compiler.hooks.done.tap("done", (compilation) => {
// 编译完成后做点什么
const configXml = new cordovaConfig("./dist/config.xml"); //根据环境改变config.xml
configXml.setElement("content", "", {
src: indexPath,
});
configXml.setPreference("debug", isDevelopment);
configXml.writeSync();
// console.log('build done');
});
},
},
],
},
// css: {
// loaderOptions: {
// sass: {
// prependData: `@import "~@/assets/css/vuetify-custom.scss"`,
// },
// scss: {
// prependData: `@import "~@/assets/css/vuetify-custom.scss";`,
// },
// },
// },
};
function getLocalIP() {
const interfaces = require("os").networkInterfaces();
for (let devName in interfaces) {
const iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
const alias = iface[i];
if (
alias.family === "IPv4" &&
alias.address !== "127.0.0.1" &&
!alias.internal
) {
return alias.address;
}
}
}
}