fastchar-appjs
Version:
快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html,不使用vue单页面功能。
953 lines (952 loc) • 37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuildOption = exports.FastInjectJsPlugin = exports.Pages = exports.System = void 0;
const tslib_1 = require("tslib");
// @ts-ignore
const fs_1 = tslib_1.__importDefault(require("fs"));
const FastHelper_1 = require("./FastHelper");
/**
* 项目相关操作
* @author Janesen
*/
class System {
/**
* 项目标题
*/
static projectTitle = "创息软件";
/**
* 项目的全局配置对象,将会自动注入到全局变量中
*/
static projectGlobalConfig = {};
/**
* 项目编辑的配置,只读 {@link BuildOption}
*/
static buildOption;
/**
* 获取默认的vue配置文件
* @param dirName 项目根目录,建议取值 {@link __dirname}
* @param options 更多选项配置 {@link BuildOption}
*/
static getDefaultVueConfig(dirName, options) {
if (options) {
this.buildOption = BuildOption.merge(options, new BuildOption());
}
else {
this.buildOption = new BuildOption();
}
if (this.buildOption.injectJsFiles) {
if (Object.prototype.toString.call(this.buildOption.injectJsFiles) === '[object Array]') {
this.buildOption.injectJsFiles.push("fastchar-appjs/FastErrorHandler");
}
else {
this.buildOption.injectJsFiles["fastchar-appjs/FastErrorHandler"] = {};
}
}
if (this.buildOption.finalParams) {
this.setFinalParams(this.buildOption.finalParams);
}
if (this.buildOption.projectTitle) {
this.projectTitle = this.buildOption.projectTitle;
}
const pages = Pages.getBuildPages(dirName, this.buildOption);
if (this.buildOption.autoCreateProjectIndexPage) {
pages["index"] = Pages.createIndexPage(JSON.stringify(pages, null, "\t"), dirName, this.buildOption);
}
this.setGlobalConfig("projectTitle", this.projectTitle);
this.setGlobalConfig("projectModel", process.env.NODE_ENV);
this.setGlobalConfig("projectVersion", process.env.npm_package_version);
this.setGlobalConfig("projectDebug", this.isServiceDebug() || this.isVueCliServerServer());
this.setGlobalConfig("nativeMobileApp", this.buildOption.nativeMobileApp);
if (this.buildOption.globalConfig) {
for (let globalConfigKey in this.buildOption.globalConfig) {
// @ts-ignore
let value = this.buildOption.globalConfig[globalConfigKey];
this.setGlobalConfig(globalConfigKey, value);
}
}
const defineValue = {
FastGlobalConfig: this.projectGlobalConfig,
BuildLevel: this.buildOption.buildLevel
};
if (this.buildOption.injectVariable) {
for (let dataKey in this.buildOption.injectVariable) {
if (this.buildOption.injectVariable[dataKey] === undefined) {
continue;
}
if (dataKey === "FastGlobalConfig") {
continue;
}
if (dataKey === "FinalParams") {
continue;
}
const value = this.buildOption.injectVariable[dataKey];
if (typeof value === 'function') {
defineValue[dataKey] = value;
}
else {
defineValue[dataKey] = JSON.stringify(value);
}
}
}
const payTypes = this.getServicePay();
if (payTypes.indexOf("ali") >= 0) {
defineValue["NativeZF1"] = (orderPrefix, orderTitle, orderMoney, orderData, callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("aliPay", [orderPrefix, orderTitle, parseFloat(orderMoney).toFixed(2), orderData], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
defineValue["NativeAuthor1"] = (callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("aliAuthor", [], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
defineValue["NativeAuthorCode1"] = (callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("aliAuthorCode", [], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
}
if (payTypes.indexOf("wx") >= 0) {
defineValue["NativeZF2"] = (orderPrefix, orderTitle, orderMoney, orderData, callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("wxPay", [orderPrefix, orderTitle, parseFloat(orderMoney).toFixed(2), orderData], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
defineValue["NativeAuthor2"] = (callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("wxAuthor", [], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
defineValue["NativeAuthorCode2"] = (callBack) => {
// @ts-ignore
return FastNative.Core.executeByPromise("wxAuthorCode", [], function (result) {
if (callBack) {
callBack(result.success, result.message, result.data);
}
});
};
}
if (!this.buildOption.cacheVueLoader && this.isVueCliServerBuild()) {
const path = require("path");
const cacheDir = path.join(dirName, this.buildOption.nodeModulesDir, ".cache", "vue-loader");
System.removeFile(cacheDir);
}
let outPageDir = this.getOutPageDir();
if (!outPageDir) {
outPageDir = this.buildOption.projectOutDir;
}
return {
outputDir: outPageDir,
assetsDir: this.buildOption.projectAssetsDir,
productionSourceMap: false,
publicPath: this.isVueCliServerBuild() ? "./" : '/',
transpileDependencies: true,
pages: pages,
css: {
extract: false, //取消css单独生成文件
},
chainWebpack: (config) => {
//版本标签加载器
config.module
.rule('vue')
.use('fastchar-appjs/src/cjs/FastVueBuilderLoader')
.loader('fastchar-appjs/src/cjs/FastVueBuilderLoader')
.options({
buildLevel: this.buildOption.buildLevel,
buildLevelTagName: this.buildOption.buildLevelTagName
}).end();
// ============压缩图片 start============
config.module
.rule('images')
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({
bypassOnDebug: true
})
.end();
// ============压缩图片 end============
if (this.buildOption.chainWebpack) {
this.buildOption.chainWebpack(config);
}
},
configureWebpack: (config) => {
if (this.buildOption.vConsole === "auto") {
if (this.isVueCliServerServer() || this.isServiceDebug()) {
const vConsolePlugin = require('vconsole-webpack-plugin');
config.plugins.push(new vConsolePlugin({
filter: [],
enable: true
}));
}
}
else if (this.buildOption.vConsole === "true" || this.buildOption.vConsole === "on") {
const vConsolePlugin = require('vconsole-webpack-plugin');
config.plugins.push(new vConsolePlugin({
filter: [],
enable: true
}));
}
if (this.isProduction() && !this.isServiceDebug()) {
try {
let targetTerser = config.optimization.minimizer[0].options.minimizer.options;
if (!targetTerser) {
targetTerser = config.optimization.minimizer[0].options.terserOptions;
}
targetTerser.compress.warnings = false;
targetTerser.compress.drop_console = true;
targetTerser.compress.drop_debugger = true;
targetTerser.compress.pure_funcs = ['console.log', 'console.debug'];
}
catch (e) {
console.error(e);
}
}
config.plugins.push(new FastInjectJsPlugin(this.buildOption));
const webpack = require("webpack");
config.plugins.push(new webpack.DefinePlugin(defineValue));
if (this.buildOption.splitChunks) {
config.optimization.splitChunks = {
cacheGroups: {
vendors: {
name: 'chunk-vendors',
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'initial'
},
common: {
name: 'chunk-common',
minChunks: 2,
priority: -20,
chunks: 'initial',
reuseExistingChunk: true
}
}
};
}
else {
config.optimization.splitChunks = false;
}
if (this.buildOption.configureWebpack) {
this.buildOption.configureWebpack(config);
}
}
};
}
/**
* 是否是 vue-cli-service build 命令构建模式
*/
static isVueCliServerBuild() {
if (process.env.npm_lifecycle_script && process.env.npm_lifecycle_script.toString().indexOf("vue-cli-service build") >= 0) {
return true;
}
return false;
}
/**
* 是否是 vue-cli-service server 命令构建模式
*/
static isVueCliServerServer() {
if (process.env.npm_lifecycle_script && process.env.npm_lifecycle_script.toString().indexOf("vue-cli-service serve") >= 0) {
return true;
}
return false;
}
/**
* 是否是正式版本,production
*/
static isProduction() {
return process.env.NODE_ENV === 'production';
}
/**
* 是否的打包开发版本,development
*/
static isDevelopment() {
return process.env.NODE_ENV === 'development';
}
/**
* 是否的打包测试版本,test
*/
static isVueTest() {
return process.env.NODE_ENV === 'test';
}
/**
* 获取运行脚本 npm_lifecycle_script 里的参数值,例如:--model production 参数名:--model 参数值:production
* @param argument
*/
static getScriptArgumentValue(argument) {
if (process.env.npm_lifecycle_script) {
const index = process.env.npm_lifecycle_script.indexOf(argument.trim());
if (index >= 0) {
const argumentVar = process.env.npm_lifecycle_script.toString().substring(index).trim();
const splitArray = argumentVar.split(" ");
if (splitArray.length > 1) {
return splitArray[1].trim();
}
return "";
}
}
return null;
}
/**
* 获取命令参数 --src
*/
static getSrcPageDir() {
return this.getScriptArgumentValue("--src");
}
/**
* 获取命令参数 --out
*/
static getOutPageDir() {
return this.getScriptArgumentValue("--out");
}
/**
* 获取命令参数 --debug 的值
*/
static isServiceDebug() {
const debugValue = this.getScriptArgumentValue("--debug");
if (debugValue == null) {
return false;
}
if (debugValue.length === 0) {
return true;
}
return debugValue === "true";
}
/**
* 获取打包支持的支付方式,避免ios上架失败,不允许支付宝支付等功能
*/
static getServicePay() {
const pay = this.getScriptArgumentValue("--pay");
if (!pay || pay.length === 0) {
return ["ali", "wx", "ios", "apple"];
}
return pay.split(",");
}
/**
* 设置全局变量值
* @param key 变量名
* @param data 变量值
*/
static setGlobalConfig(key, data) {
if (typeof data === 'function') {
this.projectGlobalConfig[key] = data;
}
else {
this.projectGlobalConfig[key] = JSON.stringify(data);
}
}
/**
* 设置FastServer请求接口的全局默认参数
* @param data 参数对象
*/
static setFinalParams(data) {
this.setGlobalConfig("FinalParams", data);
}
/**
* 彻底删除指定目录文件
* @param path
*/
static removeFile(path) {
const fs = require("fs");
let files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach((file, index) => {
let curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
System.removeFile(curPath); //递归删除文件夹
}
else {
fs.unlinkSync(curPath); //删除文件
}
});
fs.rmdirSync(path); // 删除文件夹自身
}
}
}
exports.System = System;
/**
* 页面相关操作
*/
class Pages {
/**
* 获取vue页面配置,vue.config.js 中的pages配置
* @param dirName 项目的根目录
* @param options 更多配置
*/
static getBuildPages(dirName, options) {
const fs = require("fs");
const path = require("path");
if (options) {
options = BuildOption.merge(options, new BuildOption());
}
else {
options = new BuildOption();
}
let projectPagesDir = options.projectPagesDir;
if (System.getSrcPageDir()) {
projectPagesDir = System.getSrcPageDir();
}
let pagesMap = {};
let rootPagePaths = [];
if (FastHelper_1.FastHelper.Arrays.isArray(projectPagesDir)) {
for (let projectPagesDirElement of projectPagesDir) {
rootPagePaths.push(path.join(dirName, projectPagesDirElement));
}
}
else {
rootPagePaths.push(path.join(dirName, projectPagesDir));
}
for (let rootPagePath of rootPagePaths) {
let pageFiles = fs.readdirSync(rootPagePath);
for (let i = 0; i < pageFiles.length; i++) {
let fileName = pageFiles[i];
if (fileName.indexOf(".") === 0 || fileName.indexOf("__") === 0) {
continue;
}
let vueFileName = fileName + ".vue";
let subPageDirPath = path.join(rootPagePath, fileName);
// if (System.getServiceClient() !== "all") {
// let pageConfig = this.getPageConfig(subPageDirPath, options);
// let configHasClient = false;
// if (FastHelper.Arrays.isArray(pageConfig["clients"])) {
// configHasClient = FastHelper.Arrays.exists(pageConfig["clients"], System.getServiceClient());
// }
// //如果页面的config.json里没有指定clients参数,则生成client路径值
// if (!configHasClient) {
// if (options.clientStrict || System.isServiceClientStrict()) {
// subPageDirPath = path.join(subPageDirPath, System.getServiceClient());
// } else if (fs.existsSync(path.join(subPageDirPath, System.getServiceClient()))) {
// subPageDirPath = path.join(subPageDirPath, System.getServiceClient());
// }
// }
// }
let subPageDirRelativePath = subPageDirPath.replace(dirName, "");
if (FastHelper_1.FastHelper.Strings.startWith(subPageDirRelativePath, "/")) {
subPageDirRelativePath = subPageDirRelativePath.substring(1);
}
if (!fs.existsSync(subPageDirPath)) {
continue;
}
if (fs.statSync(subPageDirPath).isFile()) {
continue;
}
let vueFilePath = path.join(subPageDirPath, vueFileName);
if (!fs.existsSync(vueFilePath)) {
vueFileName = "index.vue";
vueFilePath = path.join(subPageDirPath, vueFileName);
}
//不存在.vue的,就默认创建一个
if (!fs.existsSync(vueFilePath)) {
let content = `<script>
import {defineComponent} from 'vue'
export default defineComponent({
name: "index"
});
</script>
<template>
<div>
默认页面
</div>
</template>
<style scoped>
</style>`;
fs.writeFileSync(vueFilePath, content, {});
}
let mainFilePath = path.join(subPageDirPath, options.pageMainFileName);
if (!fs.existsSync(mainFilePath)) {
let content = "import {createApp} from \"vue\";\n" +
"import child from \"./" + vueFileName + "\";\n" +
"createApp(child).mount(\"" + options.mountSelector + "\");";
fs.writeFileSync(mainFilePath, content, {});
}
pagesMap[fileName] = {
entry: path.join(subPageDirRelativePath, options.pageMainFileName),
title: System.projectTitle,
filename: options.pageConfigHtmlNamePrefix + fileName + ".html",
};
pagesMap[fileName]["template"] = options.pageTemplateFileDir;
let pageMainTemplateFileName = path.join(subPageDirPath, options.pageMainTemplateFileName);
if (fs.existsSync(pageMainTemplateFileName)) {
pagesMap[fileName]["template"] = path.join(subPageDirRelativePath, options.pageMainTemplateFileName);
}
let configFilePath = path.join(subPageDirPath, options.pageConfigFileName);
if (fs.existsSync(configFilePath)) {
let configContent = fs.readFileSync(configFilePath);
let configObj = JSON.parse(configContent);
for (let configObjKey in configObj) {
pagesMap[fileName][configObjKey] = configObj[configObjKey];
}
}
if (options.autoCreatePageConfigFile && Object.keys(pagesMap).length > 0) {
fs.writeFileSync(configFilePath, JSON.stringify(pagesMap[fileName], null, "\t"), {});
}
}
}
return pagesMap;
}
/**
* 获取页面下config.json配置文件
* @param pagePath
* @param options
*/
static getPageConfig(pagePath, options) {
const path = require("path");
let configFilePath = path.join(pagePath, options.pageConfigFileName);
if (fs_1.default.existsSync(configFilePath)) {
const fs = require("fs");
let configContent = fs.readFileSync(configFilePath);
return JSON.parse(configContent);
}
return {};
}
/**
* 创建默认的index索引页面
* @param pagesValue
* @param dirName
* @param options
*/
static createIndexPage(pagesValue, dirName, options) {
const fs = require("fs");
const path = require("path");
if (options) {
options = BuildOption.merge(options, new BuildOption());
}
else {
options = new BuildOption();
}
let projectPagesDir = options.projectPagesDir;
if (System.getSrcPageDir()) {
projectPagesDir = System.getSrcPageDir();
}
let baseDir = path.join(dirName, projectPagesDir, "index");
// if (System.getServiceClient() !== "all") {
// if (options.clientStrict || System.isServiceClientStrict()) {
// baseDir = path.join(baseDir, System.getServiceClient());
// } else if (fs.existsSync(path.join(baseDir, System.getServiceClient()))) {
// baseDir = path.join(baseDir, System.getServiceClient());
// }
// }
if (!fs.existsSync(baseDir)) {
fs.mkdirSync(baseDir);
}
let indexJsContent = "import {createApp} from \"vue\";\n";
indexJsContent += "import main from \"./main\";\n";
indexJsContent += "let app = createApp(main);\n";
indexJsContent += "app.config.globalProperties.pages = " + pagesValue + ";\n";
indexJsContent += "app.mount(\"" + options.mountSelector + "\");";
const indexPath = path.join(baseDir, "index.js");
fs.writeFileSync(indexPath, indexJsContent, {});
let configDiv = "<template >\n" +
" <template v-for=\"(value,name) in pages\" :key=\"name\">\n" +
" <van-cell :title=\"value.filename\" is-link :url=\"value.urlParams?value.filename+'?'+value.urlParams:value.filename\" />\n" +
" </template>\n" +
"</template>\n" +
"<script>\n" +
"/* eslint-disable vue/multi-word-component-names */" +
"import {Cell} from 'vant';\n" +
"export default {\n" +
" name: \"main\",\n" +
" components: {\n" +
" [Cell.name]: Cell\n" +
" }\n" +
"}\n" +
"</script>";
fs.writeFileSync(path.join(baseDir, "main.vue"), configDiv, {});
return {
entry: indexPath,
title: System.projectTitle + "首页"
};
}
/**
* 快速复制一个vue子页面开发
* @param dirName 项目根目录
* @param copyPageName 复制目标的文件夹名
* @param newPageName 新生成的文件夹名
* @param options
*/
static copyPage(dirName, copyPageName, newPageName, options) {
if (options) {
options = BuildOption.merge(options, new BuildOption());
}
else {
options = new BuildOption();
}
const fs = require("fs");
const path = require("path");
let projectPagesDir = options.projectPagesDir;
if (System.getSrcPageDir()) {
projectPagesDir = System.getSrcPageDir();
}
let rootPath = path.join(dirName, projectPagesDir);
let copyPagePath = path.join(rootPath, copyPageName);
let newPagePath = path.join(rootPath, newPageName);
if (fs.existsSync(copyPagePath)) {
if (!fs.existsSync(newPagePath)) {
fs.mkdirSync(newPagePath);
}
let copyPageMainFilePath = path.join(copyPagePath, options.pageMainFileName);
let newPageMainFilePath = path.join(newPagePath, options.pageMainFileName);
if (fs.existsSync(copyPageMainFilePath)) {
let copyPageMainFileContent = fs.readFileSync(copyPageMainFilePath);
let newPageMainFileContent = copyPageMainFileContent.toString().replace(new RegExp(copyPageName, "g"), newPageName);
fs.writeFileSync(newPageMainFilePath, newPageMainFileContent, {});
let vueContent = "<template>\n" +
"\n" +
"</template>\n" +
"\n" +
"<script>\n" +
"export default {\n" +
" name: \"" + newPageName + "\"\n" +
"}\n" +
"</script>\n" +
"\n" +
"<style scoped>\n" +
"\n" +
"</style>";
fs.writeFileSync(path.join(newPagePath, newPageName + ".vue"), vueContent, {});
console.log("复制成功!" + newPagePath);
}
else {
console.error("目标文件夹入口文件:" + copyPageMainFilePath + " 不存在!");
}
}
else {
console.error("目标文件夹:" + copyPagePath + " 不存在!");
}
}
}
exports.Pages = Pages;
/**
* 全局注入脚本插件
*/
class FastInjectJsPlugin {
options;
constructor(options) {
this.options = options;
}
filter(key, targetFilter) {
if (targetFilter) {
if (targetFilter.include) {
for (let i = 0; i < targetFilter.include.length; i++) {
if (targetFilter.include[i] === key) {
return true;
}
}
return false;
}
if (targetFilter.exclude) {
for (let i = 0; i < targetFilter.exclude.length; i++) {
if (targetFilter.exclude[i] === key) {
return false;
}
}
}
}
return true;
}
injectArray(local, entry, targetInjectJsFiles) {
if (Object.prototype.toString.call(targetInjectJsFiles) !== '[object Array]') {
return;
}
const path = require('path');
const fs = require('fs');
for (let i = 0; i < targetInjectJsFiles.length; i++) {
let value = targetInjectJsFiles[i];
if (typeof value === 'string') {
const jsPath = path.join(local, value);
if (fs.existsSync(jsPath)) {
for (let entryKey in entry) {
if (!this.filter(entryKey, this.options.injectJsFilter)) {
continue;
}
let entryArray = entry[entryKey];
if (Object.prototype.toString.call(entryArray) === '[object Array]') {
entryArray.unshift(jsPath);
}
else if (entryArray.hasOwnProperty("import")
&& Object.prototype.toString.call(entryArray["import"]) === '[object Array]') {
entryArray["import"].unshift(jsPath);
}
}
}
}
else {
this.injectObject(local, entry, value);
}
}
}
injectObject(local, entry, targetInjectJsFiles) {
if (typeof targetInjectJsFiles !== 'object') {
return;
}
const path = require('path');
const fs = require('fs');
for (let injectJsFilesKey in targetInjectJsFiles) {
const jsPath = path.join(local, injectJsFilesKey);
if (fs.existsSync(jsPath)) {
for (let entryKey in entry) {
if (!this.filter(entryKey, targetInjectJsFiles[injectJsFilesKey])) {
continue;
}
let entryArray = entry[entryKey];
if (Object.prototype.toString.call(entryArray) === '[object Array]') {
entryArray.unshift(jsPath);
}
else if (entryArray.hasOwnProperty("import")
&& Object.prototype.toString.call(entryArray["import"]) === '[object Array]') {
entryArray["import"].unshift(jsPath);
}
}
}
}
}
apply(compiler) {
if (compiler.hooks && this.options) {
compiler.hooks.entryOption.tap({ name: 'FastInjectJsPlugin' }, (local, entry) => {
if (Object.prototype.toString.call(this.options.injectJsFiles) === '[object Array]') {
this.injectArray(local, entry, this.options.injectJsFiles);
}
else if (typeof this.options.injectJsFiles === 'object') {
this.injectObject(local, entry, this.options.injectJsFiles);
}
});
}
}
}
exports.FastInjectJsPlugin = FastInjectJsPlugin;
/**
* 获取编译配置的选项配置,配置选项如下:
* <br/>
* {@link projectTitle } 项目名称
* <br/>
* {@link projectPagesDir } 项目存储页面的目录地址 默认:src/pages
* <br/>
* {@link projectOutDir } 项目默认编译输出地址 默认:dist
* <br/>
* {@link projectAssetsDir } 项目资源路径,默认:assets
* <br/>
* {@link pageTemplateFileDir } 页面的入口文件模板地址,默认:public/index.html
* <br/>
* {@link pageMainFileName }页面目录下的入口文件名,默认:index.js
* <br/>
* {@link pageConfigHtmlNamePrefix }页面生成html文件时文件命名携带的前缀
* <br/>
* {@link pageConfigFileName } 页面目录下的配置文件名,默认:config.json
* <br/>
* {@link autoCreatePageConfigFile } 是否在每个页面目录下自动创建config.json文件
* <br/>
* {@link autoCreateProjectIndexPage } 是否自动创建项目的index页面
* <br/>
* {@link nodeModulesDir } 第三方插件存放目录文件夹,默认:node_modules
* <br/>
* {@link globalConfig } 系统的全局配置
* <br/>
* {@link finalParams } FastServer请求接口全局请求参数,web项目的全局参数优先级大于原生APP的全局参数
* <br/>
* {@link injectJsFiles } 所有页面全局注入的js文件
* <br/>
* {@link injectJsFilter } 所有页面全局注入js文件过滤器
* <br/>
* {@link injectVariable } 所有页面全局注入js变量
* <br/>
* {@link cacheVueLoader } 是否使用vue默认的cache-loader,默认使用
* <br/>
* {@link vConsole } 开启vConsole插件的方式,默认:auto。可选值:auto(自动根据编辑的类型追加,server模式或debug模式开启),true(强制开启),false(不开启)
* <br/>
* {@link splitChunks } 将公共js代码,进行分割,默认:true
* <br/>
* {@link nativeMobileApp} 项目是否应用于创息公司的手机app,默认:true
* <br/>
* {@link buildLevel} 项目编译级别,与 标签 build-level 对应
* <br/>
* {@link buildLevelTagName} 项目编译级别标签名,默认: build-level
* <br/>
* {@link chainWebpack} 配置Webpack函数function (config){};
* <br/>
* {@link configureWebpack} 配置Webpack函数function (config){};
*/
class BuildOption {
/**
* 合并options
* @param options
*/
static merge(...options) {
let newObject = {};
for (let option of options) {
for (let optionsKey in option) {
if (newObject.hasOwnProperty(optionsKey)) {
continue;
}
newObject[optionsKey] = option[optionsKey];
}
}
return newObject;
}
/**
* 项目名称
*/
projectTitle = "创息软件";
/**
* 项目存储页面的目录地址,默认src/pages 或者数组:["默认src/pages","默认src/pages2"]
*/
projectPagesDir = "src/pages/";
/**
* 项目编译输出地址,默认:dist
*/
projectOutDir = "dist";
/**
* 项目资源路径,默认:assets
*/
projectAssetsDir = "assets";
/**
* 页面的入口文件模板地址,默认:public/index.html
*/
pageTemplateFileDir = "public/index.html";
/**
* 页面目录下的入口文件名,默认:index.js
*/
pageMainFileName = "index.js";
/**
* 页面目录下的配置文件名,默认:config.json
*/
pageConfigFileName = "config.json";
/**
* 页面目录下的渲染模板html,如果存在则以这个模板进行渲染,默认:index.html
*/
pageMainTemplateFileName = "index.html";
/**
* 页面生成html文件时文件命名携带的前缀
*/
pageConfigHtmlNamePrefix = "";
/**
* 是否在每个页面目录下自动创建config.json文件
*/
autoCreatePageConfigFile = false;
/**
* 是否自动创建项目的index页面
*/
autoCreateProjectIndexPage = false;
/**
* 第三方插件存放目录文件夹,默认:node_modules
*/
nodeModulesDir = "node_modules";
/**
* vue挂载的目标节点选择器
*/
mountSelector = "#app";
/**
* 系统的全局配置,
* @example
* globalConfig:{
* mainUrl:"http://192.168.0.1:8080/test"
* }
* 可通过 :FastBaseApp.Config.getGlobalConfig("mainUrl") 在任意js中获取配置
*/
globalConfig;
/**
* FastServer请求接口全局请求参数。Web项目的全局参数优先级大于原生APP的全局参数
* @example
* finalParams:{
* userId:2,
* userName:undefined //当配置undefined值时,将排除此参数属性名
* }
*/
finalParams;
/**
* 所有页面全局注入的js文件
* @example
* injectJsFiles:["src/js/test.js","src/js/icon.js"]
* 或
* injectJsFiles:{
* "src/js/test.js":{
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
* },
* "src/js/icon.js":{
* include:["user","set"] //指定注入页面的名称,例如:user.html,set.html
* }
* }
* 或
* injectJsFiles:[
* "src/js/test.js",
* {
* "src/js/icon.js":{
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
* }
* }
* ]
*/
injectJsFiles;
/**
* 所有页面全局注入js文件过滤器,当 {@link injectJsFiles} 为数组时生效!
* @example
* injectJsFilter:{
* include:["user","set"] //指定注入页面的名称,例如:user.html,set.html
* }
* 或
* injectJsFilter:{
* exclude:["user","set"] //排除注入页面的名称,例如:user.html,set.html
* }
*/
injectJsFilter;
/**
* 所有页面全局js变量注入
* @example
* injectVariable:{
* getUserId:function(){
* return 1;
* },
* server:"……"
* }
*/
injectVariable;
/**
* 是否使用vue默认的cache-loader缓存vue-loader,如果不使用,则在build版本前将删除缓存的目录.cache/vue-loader
*/
cacheVueLoader = false;
/**
* 开启vConsole插件的方式,默认:auto。可选值:auto(自动根据编辑的类型追加,server模式或debug模式开启),true(强制开启),false(不开启)
*/
vConsole = "auto";
/**
* 将公共js代码,进行分割,默认:true
*/
splitChunks = true;
/**
* 项目是否应用于创息公司的手机app,默认:true
*/
nativeMobileApp = true;
/**
* 项目编译级别,与 标签 build-level 对应
*/
buildLevel = 1;
/**
* 编译级别的标签名,默认 build-level
*/
buildLevelTagName = "build-level";
/**
* 插入Webpack函数function (config){};
*/
chainWebpack = function () {
};
/**
* 配置Webpack函数function (config){};
*/
configureWebpack = function () {
};
}
exports.BuildOption = BuildOption;