Skip to content

Commit

Permalink
cli: 更新构建相关配置
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxiaokai3 committed Apr 19, 2021
1 parent c802b31 commit 3fcea91
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 149 deletions.
99 changes: 99 additions & 0 deletions build/default.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @description electron默认打包配置
* @author shuxiaokai
*/
const path = require("path");
const config = require("../src/config");

module.exports = {
pages: {
index: {
entry: "src/renderer/main.js", //添加了entry则不需要rendererProcessFile
template: "public/index.html",
},
},
//=====================================devserver====================================//
devServer: {
port: 9999,
},
//=====================================css相关配置====================================//
css: {
loaderOptions: {
css: {
// 这里的选项会传递给 css-loader
},
sass: {
prependData: `@import "@/scss/index.scss";`,
},
},
sourceMap: false,
},
//=====================================扩展webpack配置====================================//
configureWebpack: {
resolve: {
alias: {
"@": path.resolve(__dirname, "../src/renderer"),
"~": path.resolve(__dirname, "../"),
},
},
},
pluginOptions: {
electronBuilder: {
extends: null,
externals: [
"vue",
"axios",
"vue-electron",
"vue-router",
"vuex",
"vuex-electron",
"element-ui",
"js-cookie",
"mockjs",
"nprogress",
"monaco-editor",
"vuedraggable",
"ali-oss",
"json5",
"echarts",
"brace",
"urllib",
"cookie-parser",
"got",
"form-data",
"proxy-agent",
],
mainProcessFile: "src/main/index.js",
mainProcessWatch: ["src/main/index.js"],
builderOptions: {
productName: config.renderConfig.layout.title,
appId: "com.example.yourapp",
publish: [
{
provider: "generic",
url: "",
},
],
nsis: {
oneClick: false, // 是否一键安装
allowToChangeInstallationDirectory: true, // 允许修改安装目录
},
mac: {
icon: "build/icons/icon.icns",
},
win: {
icon: "build/icons/icon.ico",
},
linux: {
icon: "build/icons",
},
},
},
},
//=====================================eslint配置====================================//
lintOnSave: "error", //未通过eslint 禁止代码提交
//=====================================打包上线配置====================================//
publicPath: config.build.publicPath || "/",
outputDir: "dist", //输出文件类型
productionSourceMap: true, //打包时候js是否添加sourceMap
};
61 changes: 61 additions & 0 deletions build/single.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @description 默认打包配置
* @author shuxiaokai
*/
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");
const config = require("../src/config");

module.exports = {
//=====================================css相关配置====================================//
css: {
loaderOptions: {
sass: {
prependData: `@import "@/scss/index.scss";`,
},
},
extract: false,
sourceMap: false,
},
//=====================================扩展webpack配置====================================//
configureWebpack: {
resolve: {
alias: {
"@": path.resolve(__dirname, "../src/renderer"),
"~": path.resolve(__dirname, "../"),
},
},
optimization: {
splitChunks: false, // makes there only be 1 js file - leftover from earlier attempts but doesn't hurt
},
plugins: [
new HtmlWebpackPlugin({
templateParameters: {
BASE_URL: config.build.publicPath || "/",
},
filename: "index.html", // the output file name that will be created
template: "public/index.html", // this is important - a template file to use for insertion
inlineSource: ".(js|css|png|jpg|woff|ttf)$", // embed all javascript and css inline
}),
new HtmlWebpackInlineSourcePlugin(),
],
},
chainWebpack: (webpackConfig) => {
const fontsRule = webpackConfig.module.rule("fonts");
// clear all existing loaders.
// if you don't do this, the loader below will be appended to
// existing loaders of the rule.
fontsRule.uses.clear();
webpackConfig.module
.rule("fonts")
.test(/\.(ttf|otf|eot|woff|woff2)$/)
.use("base64-inline-loader")
.loader("base64-inline-loader")
.end();
},
//=====================================eslint配置====================================//
lintOnSave: "error", //未通过eslint 禁止代码提交
//=====================================打包上线配置====================================//
publicPath: config.build.publicPath || "/",
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"private": true,
"scripts": {
"dev:web": "vue-cli-service serve src/renderer/main.js",
"dev:doc-export": "vue-cli-service serve src/renderer/pages/modules/apidoc/doc-export/main.js --single",
"build:doc-offline": "vue-cli-service build src/renderer/pages/modules/apidoc/doc-export/main.js --single",
"build:doc-export": "vue-cli-service build src/renderer/pages/modules/apidoc/doc-export/main.js",
"dev:cli": "vue-cli-service serve src/renderer/main.js --cli",
"dev:doc-offline": "vue-cli-service serve src/renderer/pages/modules/apidoc/doc-export/main.js --web",
"dev:doc-share": "vue-cli-service serve src/renderer/pages/modules/apidoc/doc-export/main.js --web",
"build:doc-share": "vue-cli-service build src/renderer/pages/modules/apidoc/doc-export/main.js --web",
"build:doc-offline": "vue-cli-service build src/renderer/pages/modules/apidoc/doc-export/main.js --offline",
"build:web": "vue-cli-service build src/renderer/main.js",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
Expand Down Expand Up @@ -71,6 +73,7 @@
"eslint-plugin-vue": "^6.2.2",
"html-webpack-inline-source-plugin": "0.0.10",
"husky": "^4.3.0",
"minimist": "^1.2.5",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.5",
Expand Down
166 changes: 20 additions & 146 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,159 +1,33 @@
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");
const minimist = require("minimist");
const config = require("./src/config");
const defaultBuildConfig = require("./build/default.build");
const singleBuildConfig = require("./build/single.build");

process.env.VUE_APP_TITLE = config.renderConfig.layout.title;
const isShareDoc = process.argv.find((val) => val === "--single");
const rawArgv = process.argv.slice(2);
const argv = minimist(rawArgv);
const buildWebPage = argv.web; //在线连接和生成静态HTML页面
const buildSingleWebPage = argv.offline; //仅生成单个文件

let vueConfig = {};
if (isShareDoc) {
vueConfig = {
//=====================================css相关配置====================================//
css: {
loaderOptions: {
sass: {
prependData: `@import "@/scss/index.scss";`,
},
},
extract: false,
sourceMap: false,
},
//=====================================扩展webpack配置====================================//
configureWebpack: {
resolve: {
alias: {
"@": path.resolve(__dirname, "src/renderer"),
"~": path.resolve(__dirname, ""),
},
},
optimization: {
splitChunks: false, // makes there only be 1 js file - leftover from earlier attempts but doesn't hurt
},
plugins: [
new HtmlWebpackPlugin({
templateParameters: {
BASE_URL: config.build.publicPath || "/",
},
filename: "index.html", // the output file name that will be created
template: "public/index.html", // this is important - a template file to use for insertion
inlineSource: ".(js|css|png|jpg|woff|ttf)$", // embed all javascript and css inline
}),
new HtmlWebpackInlineSourcePlugin(),
],
},
chainWebpack: (webpackConfig) => {
const fontsRule = webpackConfig.module.rule("fonts");
// clear all existing loaders.
// if you don't do this, the loader below will be appended to
// existing loaders of the rule.
fontsRule.uses.clear();
webpackConfig.module
.rule("fonts")
.test(/\.(ttf|otf|eot|woff|woff2)$/)
.use("base64-inline-loader")
.loader("base64-inline-loader")
.end();
},
//=====================================eslint配置====================================//
lintOnSave: "error", //未通过eslint 禁止代码提交
//=====================================打包上线配置====================================//
publicPath: config.build.publicPath || "/",
// outputDir: "dist", //输出文件类型
};
if (buildSingleWebPage) {
vueConfig = singleBuildConfig;
} else if (buildWebPage) {
delete defaultBuildConfig.pages;
vueConfig = defaultBuildConfig;
} else {
vueConfig = {
pages: {
index: {
entry: "src/renderer/main.js", //添加了entry则不需要rendererProcessFile
template: "public/index.html",
defaultBuildConfig.css = {
loaderOptions: {
css: {
// 这里的选项会传递给 css-loader
},
},
//=====================================devserver====================================//
devServer: {
port: 9999,
},
//=====================================css相关配置====================================//
css: {
loaderOptions: {
css: {
// 这里的选项会传递给 css-loader
},
sass: {
prependData: `@import "@/scss/index.scss";`,
},
},
sourceMap: false,
},
//=====================================扩展webpack配置====================================//
configureWebpack: {
resolve: {
alias: {
"@": path.resolve(__dirname, "src/renderer"),
"~": path.resolve(__dirname, ""),
},
},
},
pluginOptions: {
electronBuilder: {
extends: null,
externals: [
"vue",
"axios",
"vue-electron",
"vue-router",
"vuex",
"vuex-electron",
"element-ui",
"js-cookie",
"mockjs",
"nprogress",
"monaco-editor",
"vuedraggable",
"ali-oss",
"json5",
"echarts",
"brace",
"urllib",
"cookie-parser",
"got",
"form-data",
"proxy-agent",
],
mainProcessFile: "src/main/index.js",
mainProcessWatch: ["src/main/index.js"],
builderOptions: {
productName: config.renderConfig.layout.title,
appId: "com.example.yourapp",
publish: [
{
provider: "generic",
url: "",
},
],
nsis: {
oneClick: false, // 是否一键安装
allowToChangeInstallationDirectory: true, // 允许修改安装目录
},
mac: {
icon: "build/icons/icon.icns",
},
win: {
icon: "build/icons/icon.ico",
},
linux: {
icon: "build/icons",
},
},
sass: {
prependData: `@import "@/scss/index.scss";`,
},
},
//=====================================eslint配置====================================//
lintOnSave: "error", //未通过eslint 禁止代码提交
//=====================================打包上线配置====================================//
publicPath: config.build.publicPath || "/",
outputDir: "dist", //输出文件类型
productionSourceMap: true, //打包时候js是否添加sourceMap
sourceMap: false,
};
vueConfig = defaultBuildConfig
}

module.exports = vueConfig;

0 comments on commit 3fcea91

Please sign in to comment.