fast-vue-multi-pages 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/cjs/FastVueMultiTool.d.ts +60 -0
- package/dist/cjs/FastVueMultiTool.js +65 -0
- package/dist/cjs/http/FastVueMultiCookie.d.ts +18 -0
- package/dist/cjs/http/FastVueMultiCookie.js +30 -0
- package/dist/cjs/http/FastVueMultiHttp.d.ts +225 -0
- package/dist/cjs/http/FastVueMultiHttp.js +572 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/loader/FastTagBuilderLoader.d.ts +2 -0
- package/dist/cjs/loader/FastTagBuilderLoader.js +89 -0
- package/dist/cjs/other/FastVueMultiBoolean.d.ts +13 -0
- package/dist/cjs/other/FastVueMultiBoolean.js +56 -0
- package/dist/cjs/other/FastVueMultiClipboard.d.ts +21 -0
- package/dist/cjs/other/FastVueMultiClipboard.js +38 -0
- package/dist/cjs/other/FastVueMultiDate.d.ts +30 -0
- package/dist/cjs/other/FastVueMultiDate.js +166 -0
- package/dist/cjs/other/FastVueMultiElement.d.ts +46 -0
- package/dist/cjs/other/FastVueMultiElement.js +154 -0
- package/dist/cjs/other/FastVueMultiFunction.d.ts +19 -0
- package/dist/cjs/other/FastVueMultiFunction.js +68 -0
- package/dist/cjs/other/FastVueMultiStore.d.ts +13 -0
- package/dist/cjs/other/FastVueMultiStore.js +23 -0
- package/dist/cjs/other/FastVueMultiWindow.d.ts +21 -0
- package/dist/cjs/other/FastVueMultiWindow.js +53 -0
- package/dist/cjs/store/FastVueMultiStore.d.ts +13 -0
- package/dist/cjs/store/FastVueMultiStore.js +23 -0
- package/dist/cjs/vue/FastVueMultiConfig.d.ts +18 -0
- package/dist/cjs/vue/FastVueMultiConfig.js +43 -0
- package/dist/esm/FastVueMultiTool.d.ts +60 -0
- package/dist/esm/FastVueMultiTool.js +59 -0
- package/dist/esm/http/FastVueMultiCookie.d.ts +18 -0
- package/dist/esm/http/FastVueMultiCookie.js +34 -0
- package/dist/esm/http/FastVueMultiHttp.d.ts +225 -0
- package/dist/esm/http/FastVueMultiHttp.js +608 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/loader/FastTagBuilderLoader.d.ts +2 -0
- package/dist/esm/loader/FastTagBuilderLoader.js +89 -0
- package/dist/esm/other/FastVueMultiBoolean.d.ts +13 -0
- package/dist/esm/other/FastVueMultiBoolean.js +60 -0
- package/dist/esm/other/FastVueMultiClipboard.d.ts +21 -0
- package/dist/esm/other/FastVueMultiClipboard.js +56 -0
- package/dist/esm/other/FastVueMultiDate.d.ts +30 -0
- package/dist/esm/other/FastVueMultiDate.js +170 -0
- package/dist/esm/other/FastVueMultiElement.d.ts +46 -0
- package/dist/esm/other/FastVueMultiElement.js +158 -0
- package/dist/esm/other/FastVueMultiFunction.d.ts +19 -0
- package/dist/esm/other/FastVueMultiFunction.js +97 -0
- package/dist/esm/other/FastVueMultiStore.d.ts +13 -0
- package/dist/esm/other/FastVueMultiStore.js +27 -0
- package/dist/esm/other/FastVueMultiWindow.d.ts +21 -0
- package/dist/esm/other/FastVueMultiWindow.js +57 -0
- package/dist/esm/store/FastVueMultiStore.d.ts +13 -0
- package/dist/esm/store/FastVueMultiStore.js +27 -0
- package/dist/esm/vue/FastVueMultiConfig.d.ts +18 -0
- package/dist/esm/vue/FastVueMultiConfig.js +48 -0
- package/package.json +64 -0
- package/vue/FastBuildOption.d.ts +241 -0
- package/vue/FastBuildOption.js +249 -0
- package/vue/FastInjectJsPlugin.d.ts +11 -0
- package/vue/FastInjectJsPlugin.js +101 -0
- package/vue/FastPages.d.ts +25 -0
- package/vue/FastPages.js +173 -0
- package/vue/FastVueMultiConfig.d.ts +18 -0
- package/vue/FastVueMultiConfig.js +43 -0
- package/vue/FastVueMultiPages.d.ts +62 -0
- package/vue/FastVueMultiPages.js +294 -0
- package/vue/index.d.ts +2 -0
- package/vue/index.js +5 -0
@@ -0,0 +1,294 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastVueMultiPages = void 0;
|
4
|
+
const FastBuildOption_1 = require("./FastBuildOption");
|
5
|
+
const FastPages_1 = require("./FastPages");
|
6
|
+
const FastInjectJsPlugin_1 = require("./FastInjectJsPlugin");
|
7
|
+
/**
|
8
|
+
* 项目相关操作
|
9
|
+
* @author Janesen
|
10
|
+
*/
|
11
|
+
class FastVueMultiPages {
|
12
|
+
static projectGlobalConfig = {};
|
13
|
+
/**
|
14
|
+
* 获取默认的vue配置文件
|
15
|
+
* @param dirName 项目根目录,建议取值 {@link __dirname}
|
16
|
+
* @param options 更多选项配置 {@link FastBuildOption}
|
17
|
+
*/
|
18
|
+
static getDefaultVueConfig(dirName, options) {
|
19
|
+
if (options) {
|
20
|
+
options = FastBuildOption_1.FastBuildOption.merge(options, new FastBuildOption_1.FastBuildOption());
|
21
|
+
}
|
22
|
+
if (options.httpFinalParams) {
|
23
|
+
this.setGlobalConfig("httpFinalParams", options.httpFinalParams);
|
24
|
+
}
|
25
|
+
if (options.httpFinalHeaders) {
|
26
|
+
this.setGlobalConfig("httpFinalHeaders", options.httpFinalHeaders);
|
27
|
+
}
|
28
|
+
if (options.httpBeforeRequest) {
|
29
|
+
this.setGlobalConfig("httpBeforeRequest", options.httpBeforeRequest);
|
30
|
+
}
|
31
|
+
if (options.httpAfterRequest) {
|
32
|
+
this.setGlobalConfig("httpAfterRequest", options.httpAfterRequest);
|
33
|
+
}
|
34
|
+
const pages = FastPages_1.FastPages.getBuildPages(dirName, options);
|
35
|
+
if (options.autoCreateProjectIndexPage) {
|
36
|
+
pages["index"] = FastPages_1.FastPages.createIndexPage(JSON.stringify(pages, null, "\t"), dirName, options);
|
37
|
+
}
|
38
|
+
this.setGlobalConfig("projectTitle", options.projectTitle);
|
39
|
+
this.setGlobalConfig("projectModel", process.env.NODE_ENV);
|
40
|
+
this.setGlobalConfig("projectVersion", process.env.npm_package_version);
|
41
|
+
this.setGlobalConfig("projectDebug", this.isServiceDebug() || this.isVueCliServerServer());
|
42
|
+
if (options.globalConfig) {
|
43
|
+
for (let globalConfigKey in options.globalConfig) {
|
44
|
+
// @ts-ignore
|
45
|
+
globalConfig[globalConfigKey] = options.globalConfig[globalConfigKey];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
const defineValue = {
|
49
|
+
SystemGlobalConfig: this.projectGlobalConfig,
|
50
|
+
BuildLevel: options.buildLevel
|
51
|
+
};
|
52
|
+
if (options.injectVariable) {
|
53
|
+
for (let dataKey in options.injectVariable) {
|
54
|
+
if (options.injectVariable[dataKey] === undefined) {
|
55
|
+
continue;
|
56
|
+
}
|
57
|
+
if (dataKey === "SystemGlobalConfig") {
|
58
|
+
continue;
|
59
|
+
}
|
60
|
+
if (dataKey === "FinalParams") {
|
61
|
+
continue;
|
62
|
+
}
|
63
|
+
const value = options.injectVariable[dataKey];
|
64
|
+
if (typeof value === 'function') {
|
65
|
+
defineValue[dataKey] = value;
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
defineValue[dataKey] = JSON.stringify(value);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
if (!options.cacheVueLoader && this.isVueCliServerBuild()) {
|
73
|
+
const path = require("path");
|
74
|
+
const cacheDir = path.join(dirName, options.nodeModulesDir, ".cache", "vue-loader");
|
75
|
+
this.removeFile(cacheDir);
|
76
|
+
}
|
77
|
+
let outPageDir = this.getOutPageDir();
|
78
|
+
if (!outPageDir) {
|
79
|
+
outPageDir = options.projectOutDir;
|
80
|
+
}
|
81
|
+
const { defineConfig } = require('@vue/cli-service');
|
82
|
+
return defineConfig({
|
83
|
+
outputDir: outPageDir,
|
84
|
+
assetsDir: options.projectAssetsDir,
|
85
|
+
productionSourceMap: false,
|
86
|
+
publicPath: this.isVueCliServerBuild() ? "./" : '/',
|
87
|
+
transpileDependencies: true,
|
88
|
+
pages: pages,
|
89
|
+
css: {
|
90
|
+
extract: false, //取消css单独生成文件
|
91
|
+
},
|
92
|
+
chainWebpack: (config) => {
|
93
|
+
let tagLoaderPath = "fast-vue-multi-pages/dist/cjs/loader/FastTagBuilderLoader";
|
94
|
+
//版本标签加载器
|
95
|
+
config.module
|
96
|
+
.rule('vue')
|
97
|
+
.use(tagLoaderPath)
|
98
|
+
.loader(tagLoaderPath)
|
99
|
+
.options({
|
100
|
+
buildLevel: options.buildLevel,
|
101
|
+
buildLevelTagName: options.buildLevelTagName
|
102
|
+
}).end();
|
103
|
+
// ============压缩图片 start============
|
104
|
+
config.module
|
105
|
+
.rule('images')
|
106
|
+
.use('image-webpack-loader')
|
107
|
+
.loader('image-webpack-loader')
|
108
|
+
.options({
|
109
|
+
bypassOnDebug: true
|
110
|
+
})
|
111
|
+
.end();
|
112
|
+
// ============压缩图片 end============
|
113
|
+
if (options.chainWebpack) {
|
114
|
+
options.chainWebpack(config);
|
115
|
+
}
|
116
|
+
},
|
117
|
+
configureWebpack: (config) => {
|
118
|
+
if (options.vConsole === "auto") {
|
119
|
+
if (this.isVueCliServerServer() || this.isServiceDebug()) {
|
120
|
+
const vConsolePlugin = require('vconsole-webpack-plugin');
|
121
|
+
config.plugins.push(new vConsolePlugin({
|
122
|
+
filter: [],
|
123
|
+
enable: true
|
124
|
+
}));
|
125
|
+
}
|
126
|
+
}
|
127
|
+
else if (options.vConsole === "true" || options.vConsole === "on") {
|
128
|
+
const vConsolePlugin = require('vconsole-webpack-plugin');
|
129
|
+
config.plugins.push(new vConsolePlugin({
|
130
|
+
filter: [],
|
131
|
+
enable: true
|
132
|
+
}));
|
133
|
+
}
|
134
|
+
if (this.isProduction() && !this.isServiceDebug()) {
|
135
|
+
try {
|
136
|
+
let targetTerser = config.optimization.minimizer[0].options.minimizer.options;
|
137
|
+
if (!targetTerser) {
|
138
|
+
targetTerser = config.optimization.minimizer[0].options.terserOptions;
|
139
|
+
}
|
140
|
+
targetTerser.compress.warnings = false;
|
141
|
+
targetTerser.compress.drop_console = true;
|
142
|
+
targetTerser.compress.drop_debugger = true;
|
143
|
+
targetTerser.compress.pure_funcs = ['console.log', 'console.debug', 'console.error'];
|
144
|
+
}
|
145
|
+
catch (e) {
|
146
|
+
console.error(e);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
config.plugins.push(new FastInjectJsPlugin_1.FastInjectJsPlugin(options));
|
150
|
+
const webpack = require("webpack");
|
151
|
+
config.plugins.push(new webpack.DefinePlugin(defineValue));
|
152
|
+
if (options.splitChunks) {
|
153
|
+
config.optimization.splitChunks = {
|
154
|
+
cacheGroups: {
|
155
|
+
vendors: {
|
156
|
+
name: 'chunk-vendors',
|
157
|
+
test: /[\\/]node_modules[\\/]/,
|
158
|
+
priority: -10,
|
159
|
+
chunks: 'initial'
|
160
|
+
},
|
161
|
+
common: {
|
162
|
+
name: 'chunk-common',
|
163
|
+
minChunks: 2,
|
164
|
+
priority: -20,
|
165
|
+
chunks: 'initial',
|
166
|
+
reuseExistingChunk: true
|
167
|
+
}
|
168
|
+
}
|
169
|
+
};
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
config.optimization.splitChunks = false;
|
173
|
+
}
|
174
|
+
if (options.configureWebpack) {
|
175
|
+
options.configureWebpack(config);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
});
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* 设置全局变量值
|
182
|
+
* @param key 变量名
|
183
|
+
* @param data 变量值
|
184
|
+
*/
|
185
|
+
static setGlobalConfig(key, data) {
|
186
|
+
if (typeof data === 'function') {
|
187
|
+
this.projectGlobalConfig[key] = data;
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
this.projectGlobalConfig[key] = JSON.stringify(data);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
/**
|
194
|
+
* 是否是 vue-cli-service build 命令构建模式
|
195
|
+
*/
|
196
|
+
static isVueCliServerBuild() {
|
197
|
+
if (process.env.npm_lifecycle_script && process.env.npm_lifecycle_script.toString().indexOf("vue-cli-service build") >= 0) {
|
198
|
+
return true;
|
199
|
+
}
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
/**
|
203
|
+
* 是否是 vue-cli-service server 命令构建模式
|
204
|
+
*/
|
205
|
+
static isVueCliServerServer() {
|
206
|
+
if (process.env.npm_lifecycle_script && process.env.npm_lifecycle_script.toString().indexOf("vue-cli-service serve") >= 0) {
|
207
|
+
return true;
|
208
|
+
}
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
/**
|
212
|
+
* 是否是正式版本,production
|
213
|
+
*/
|
214
|
+
static isProduction() {
|
215
|
+
return process.env.NODE_ENV === 'production';
|
216
|
+
}
|
217
|
+
/**
|
218
|
+
* 是否的打包开发版本,development
|
219
|
+
*/
|
220
|
+
static isDevelopment() {
|
221
|
+
return process.env.NODE_ENV === 'development';
|
222
|
+
}
|
223
|
+
/**
|
224
|
+
* 是否的打包测试版本,test
|
225
|
+
*/
|
226
|
+
static isVueTest() {
|
227
|
+
return process.env.NODE_ENV === 'test';
|
228
|
+
}
|
229
|
+
/**
|
230
|
+
* 获取运行脚本 npm_lifecycle_script 里的参数值,例如:--model production 参数名:--model 参数值:production
|
231
|
+
* @param argument
|
232
|
+
*/
|
233
|
+
static getScriptArgumentValue(argument) {
|
234
|
+
if (process.env.npm_lifecycle_script) {
|
235
|
+
const index = process.env.npm_lifecycle_script.indexOf(argument.trim());
|
236
|
+
if (index >= 0) {
|
237
|
+
const argumentVar = process.env.npm_lifecycle_script.toString().substring(index).trim();
|
238
|
+
const splitArray = argumentVar.split(" ");
|
239
|
+
if (splitArray.length > 1) {
|
240
|
+
return splitArray[1].trim();
|
241
|
+
}
|
242
|
+
return "";
|
243
|
+
}
|
244
|
+
}
|
245
|
+
return null;
|
246
|
+
}
|
247
|
+
/**
|
248
|
+
* 获取命令参数 --src
|
249
|
+
*/
|
250
|
+
static getSrcPageDir() {
|
251
|
+
return this.getScriptArgumentValue("--src");
|
252
|
+
}
|
253
|
+
/**
|
254
|
+
* 获取命令参数 --out
|
255
|
+
*/
|
256
|
+
static getOutPageDir() {
|
257
|
+
return this.getScriptArgumentValue("--out");
|
258
|
+
}
|
259
|
+
/**
|
260
|
+
* 获取命令参数 --debug 的值
|
261
|
+
*/
|
262
|
+
static isServiceDebug() {
|
263
|
+
const debugValue = this.getScriptArgumentValue("--debug");
|
264
|
+
if (debugValue == null) {
|
265
|
+
return false;
|
266
|
+
}
|
267
|
+
if (debugValue.length === 0) {
|
268
|
+
return true;
|
269
|
+
}
|
270
|
+
return debugValue === "true";
|
271
|
+
}
|
272
|
+
/**
|
273
|
+
* 彻底删除指定目录文件
|
274
|
+
* @param path
|
275
|
+
*/
|
276
|
+
static removeFile(path) {
|
277
|
+
const fs = require("fs");
|
278
|
+
let files = [];
|
279
|
+
if (fs.existsSync(path)) {
|
280
|
+
files = fs.readdirSync(path);
|
281
|
+
files.forEach((file, index) => {
|
282
|
+
let curPath = path + "/" + file;
|
283
|
+
if (fs.statSync(curPath).isDirectory()) {
|
284
|
+
this.removeFile(curPath); //递归删除文件夹
|
285
|
+
}
|
286
|
+
else {
|
287
|
+
fs.unlinkSync(curPath); //删除文件
|
288
|
+
}
|
289
|
+
});
|
290
|
+
fs.rmdirSync(path); // 删除文件夹自身
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
exports.FastVueMultiPages = FastVueMultiPages;
|
package/vue/index.d.ts
ADDED
package/vue/index.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FastVueMultiPages = void 0;
|
4
|
+
const FastVueMultiPages_1 = require("./FastVueMultiPages");
|
5
|
+
Object.defineProperty(exports, "FastVueMultiPages", { enumerable: true, get: function () { return FastVueMultiPages_1.FastVueMultiPages; } });
|