Commit 90d69592 by Jaxon

chron: 项目基本配置 - 2

1 parent d0029f56
...@@ -6,6 +6,9 @@ node_modules ...@@ -6,6 +6,9 @@ node_modules
.env.local .env.local
.env.*.local .env.*.local
.vscode/changelists.json
# Log files # Log files
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
"cSpell.words": [ "cSpell.words": [
"vuex", "vuex",
"Cascader", "Cascader",
"glsx" "glsx",
"wecom"
], ],
"workbench.tree.indent": 24, "workbench.tree.indent": 24,
"explorer.compactFolders": false, "explorer.compactFolders": false,
......
File mode changed
import antfu from "@antfu/eslint-config"; import antfu from "@antfu/eslint-config";
export default antfu({ export default antfu(
{
markdown: true, markdown: true,
vue: true, vue: true,
css: true, css: true,
...@@ -27,7 +28,9 @@ export default antfu({ ...@@ -27,7 +28,9 @@ export default antfu({
"semi": true, "semi": true,
"array-bracket-spacing": ["error", "always"], "array-bracket-spacing": ["error", "always"],
}, },
rules: { rules: {
"node/prefer-global/process": "off",
"vue/no-deprecated-v-on-native-modifier": "off", "vue/no-deprecated-v-on-native-modifier": "off",
"vue/no-deprecated-destroyed-lifecycle": "off", "vue/no-deprecated-destroyed-lifecycle": "off",
"vue/no-deprecated-model-definition": "off", "vue/no-deprecated-model-definition": "off",
...@@ -162,4 +165,21 @@ export default antfu({ ...@@ -162,4 +165,21 @@ export default antfu({
*/ */
html: true, html: true,
}, },
}); },
{
files: [
"vue.config.js",
"*.config.js",
"scripts/**/*.{js,cjs,mjs}",
],
languageOptions: {
globals: {
process: "readonly",
module: "readonly",
require: "readonly",
__dirname: "readonly",
__filename: "readonly",
},
},
},
);
{ {
"name": "supervise-wecom", "name": "supervise-wecom",
"type": "module",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"description": "supervise-wecom", "description": "supervise-wecom",
...@@ -30,7 +31,6 @@ ...@@ -30,7 +31,6 @@
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^6.7.3", "@antfu/eslint-config": "^6.7.3",
"@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0", "@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0", "@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0", "@vue/cli-service": "~4.5.0",
......
...@@ -25,6 +25,6 @@ ...@@ -25,6 +25,6 @@
this.bus.$off(‘事件名’); this.bus.$off(‘事件名’);
}, },
*/ */
import Vue from 'vue' import Vue from "vue";
export default new Vue() export default new Vue();
'use strict' "use strict";
const path = require('path') const path = require("node:path");
const defaultSettings = require('./src/config/conf.js') const defaultSettings = require("./src/config/conf.js");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const resolve = dir => path.join(__dirname, dir) const resolve = dir => path.join(__dirname, dir);
// page title // page title
const name = defaultSettings.title || '登录中...' const name = defaultSettings.title || "登录中...";
// 生产环境,测试和正式 // 生产环境,测试和正式
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV) const IS_PROD = ["production", "prod"].includes(process.env.NODE_ENV);
/** /**
* 雪碧图插件 * 雪碧图插件
*/ */
const SpritesmithPlugin = require('webpack-spritesmith') const SpritesmithPlugin = require("webpack-spritesmith");
const spritesmithFunction = data => {
const { spritesheet, sprites } = data function spritesmithFunction(data) {
const shared = `.sprite-icon { background-image: url(${data.sprites[0].image});background-size: ${spritesheet.width / 2}px ${spritesheet.height / 2}px;}` const { spritesheet, sprites } = data;
const shared = `.sprite-icon { background-image: url(${data.sprites[0].image});background-size: ${spritesheet.width / 2}px ${spritesheet.height / 2}px;}`;
const perSprite = sprites const perSprite = sprites
.map(sprite => { .map((sprite) => {
const { name, width, height, offset_x, offset_y } = sprite const { name, width, height, offset_x, offset_y } = sprite;
return `.icon-${name} { width: ${width / 2}px; height: ${height / 2}px; background-position: ${offset_x / 2}px ${offset_y / 2}px;}` return `.icon-${name} { width: ${width / 2}px; height: ${height / 2}px; background-position: ${offset_x / 2}px ${offset_y / 2}px;}`;
}) })
.join('\n') .join("\n");
return `${shared}\n${perSprite}` return `${shared}\n${perSprite}`;
} }
module.exports = { module.exports = {
publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-main-cwq/', // 署应用包时的基本 URL。 vue-router hash 模式使用 // 署应用包时的基本 URL。 vue-router hash 模式使用
publicPath: IS_PROD ? "./" : "/dj-scrm-wx-work-main-cwq/",
// publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-lwk/', // 署应用包时的基本 URL。 vue-router hash 模式使用 // publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-lwk/', // 署应用包时的基本 URL。 vue-router hash 模式使用
// publicPath: '/dj-scrm-wx-work-main/', // 署应用包时的基本 URL。 vue-router history模式使用 微信开发环境需打开 // publicPath: '/dj-scrm-wx-work-main/', // 署应用包时的基本 URL。 vue-router history模式使用 微信开发环境需打开
outputDir: 'dist', // 生产环境构建文件的目录 outputDir: "dist",
assetsDir: 'static', // outputDir的静态资源(js、css、img、fonts)目录 assetsDir: "static",
lintOnSave: !IS_PROD, lintOnSave: false,
productionSourceMap: false, // 如果不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。 productionSourceMap: false, // 如果不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
devServer: { devServer: {
disableHostCheck: true, disableHostCheck: true,
...@@ -44,8 +46,8 @@ module.exports = { ...@@ -44,8 +46,8 @@ module.exports = {
overlay: { overlay: {
// 当出现编译器错误或警告时,在浏览器中显示全屏覆盖层 // 当出现编译器错误或警告时,在浏览器中显示全屏覆盖层
warnings: false, warnings: false,
errors: true errors: true,
} },
// proxy: { // proxy: {
// //配置跨域 // //配置跨域
// '/api': { // '/api': {
...@@ -59,7 +61,8 @@ module.exports = { ...@@ -59,7 +61,8 @@ module.exports = {
// } // }
}, },
css: { css: {
extract: IS_PROD, // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。 // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。
extract: IS_PROD,
sourceMap: false, sourceMap: false,
loaderOptions: { loaderOptions: {
scss: { scss: {
...@@ -67,47 +70,47 @@ module.exports = { ...@@ -67,47 +70,47 @@ module.exports = {
// 详情: https://cli.vuejs.org/guide/css.html#passing-options-to-pre-processor-loaders // 详情: https://cli.vuejs.org/guide/css.html#passing-options-to-pre-processor-loaders
prependData: ` prependData: `
$cdn: "${defaultSettings.cdn}"; $cdn: "${defaultSettings.cdn}";
` `,
} },
} },
}, },
configureWebpack: config => { configureWebpack: (config) => {
config.name = name config.name = name;
config.resolve.modules = ['node_modules', './src/assets/spritesmith'] config.resolve.modules = ["node_modules", "./src/assets/spritesmith"];
const Plugins = [ const Plugins = [
new SpritesmithPlugin({ new SpritesmithPlugin({
// 引入图片文件夹 // 引入图片文件夹
src: { src: {
cwd: path.resolve(__dirname, './src/assets/spritesmith'), cwd: path.resolve(__dirname, "./src/assets/spritesmith"),
glob: ['*.png', '*.jpg'] glob: ["*.png", "*.jpg"],
}, },
// 生成图片的路径 // 生成图片的路径
target: { target: {
image: path.resolve(__dirname, './src/assets/images/sprite.png'), image: path.resolve(__dirname, "./src/assets/images/sprite.png"),
// 生成SCSS // 生成SCSS
css: [ css: [
[ [
path.resolve(__dirname, './src/assets/css/sprite.scss'), path.resolve(__dirname, "./src/assets/css/sprite.scss"),
{ {
format: 'function_based_template' format: "function_based_template",
} },
] ],
] ],
}, },
customTemplates: { customTemplates: {
function_based_template: spritesmithFunction function_based_template: spritesmithFunction,
}, },
// background引用路径 // background引用路径
apiOptions: { apiOptions: {
cssImageRef: '../images/sprite.png' cssImageRef: "../images/sprite.png",
}, },
// 每个图片间距 // 每个图片间距
spritesmithOptions: { spritesmithOptions: {
padding: 20 padding: 20,
} },
}) }),
] ];
config.plugins = [...config.plugins, ...Plugins] config.plugins = [...config.plugins, ...Plugins];
// 为生产环境修改配置... // 为生产环境修改配置...
// if (IS_PROD) { // if (IS_PROD) {
// // externals // // externals
...@@ -115,82 +118,82 @@ module.exports = { ...@@ -115,82 +118,82 @@ module.exports = {
// } // }
}, },
chainWebpack: config => { chainWebpack: (config) => {
config.plugins.delete('preload') // TODO: need test config.plugins.delete("preload"); // TODO: need test
config.plugins.delete('prefetch') // TODO: need test config.plugins.delete("prefetch"); // TODO: need test
// 别名 alias // 别名 alias
config.resolve.alias config.resolve.alias
.set('@', resolve('src')) .set("@", resolve("src"))
.set('assets', resolve('src/assets')) .set("assets", resolve("src/assets"))
.set('api', resolve('src/api')) .set("api", resolve("src/api"))
.set('views', resolve('src/views')) .set("views", resolve("src/views"))
.set('components', resolve('src/components')) .set("components", resolve("src/components"))
.set('plugins', resolve('src/components')) .set("plugins", resolve("src/components"))
.set('utils', resolve('src/utils')) .set("utils", resolve("src/utils"));
/** /**
* 设置保留空格 * 设置保留空格
*/ */
config.module config.module
.rule('vue') .rule("vue")
.use('vue-loader') .use("vue-loader")
.loader('vue-loader') .loader("vue-loader")
.tap(options => { .tap((options) => {
options.compilerOptions.preserveWhitespace = true options.compilerOptions.preserveWhitespace = true;
return options return options;
}) })
.end() .end();
/** /**
* 打包分析 * 打包分析
*/ */
if (IS_PROD) { if (IS_PROD) {
config.plugin('webpack-report').use(BundleAnalyzerPlugin, [ config.plugin("webpack-report").use(BundleAnalyzerPlugin, [
{ {
analyzerMode: 'static' analyzerMode: "static",
} },
]) ]);
} }
config config
// https://webpack.js.org/configuration/devtool/#development // https://webpack.js.org/configuration/devtool/#development
.when(!IS_PROD, config => config.devtool('cheap-source-map')) .when(!IS_PROD, config => config.devtool("cheap-source-map"));
config.when(IS_PROD, config => { config.when(IS_PROD, (config) => {
config config
.plugin('ScriptExtHtmlWebpackPlugin') .plugin("ScriptExtHtmlWebpackPlugin")
.after('html') .after("html")
.use('script-ext-html-webpack-plugin', [ .use("script-ext-html-webpack-plugin", [
{ {
// 将 runtime 作为内联引入不单独存在 // 将 runtime 作为内联引入不单独存在
inline: /runtime\..*\.js$/ inline: /runtime\..*\.js$/,
} },
]) ])
.end() .end();
config.optimization.splitChunks({ config.optimization.splitChunks({
chunks: 'all', chunks: "all",
cacheGroups: { cacheGroups: {
// cacheGroups 下可以可以配置多个组,每个组根据test设置条件,符合test条件的模块 // cacheGroups 下可以可以配置多个组,每个组根据test设置条件,符合test条件的模块
commons: { commons: {
name: 'chunk-commons', name: "chunk-commons",
test: resolve('src/components'), test: resolve("src/components"),
minChunks: 3, // 被至少用三次以上打包分离 minChunks: 3, // 被至少用三次以上打包分离
priority: 5, // 优先级 priority: 5, // 优先级
reuseExistingChunk: true // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。 reuseExistingChunk: true, // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。
}, },
node_vendors: { node_vendors: {
name: 'chunk-libs', name: "chunk-libs",
chunks: 'initial', // 只打包初始时依赖的第三方 chunks: "initial", // 只打包初始时依赖的第三方
test: /[\\/]node_modules[\\/]/, test: /[\\/]node_modules[\\/]/,
priority: 10 priority: 10,
}, },
vantUI: { vantUI: {
name: 'chunk-vantUI', // 单独将 vantUI 拆包 name: "chunk-vantUI", // 单独将 vantUI 拆包
priority: 20, // 数字大权重到,满足多个 cacheGroups 的条件时候分到权重高的 priority: 20, // 数字大权重到,满足多个 cacheGroups 的条件时候分到权重高的
test: /[\\/]node_modules[\\/]_?vant(.*)/ test: /[\\/]node_modules[\\/]_?vant(.*)/,
} },
} },
}) });
config.optimization.runtimeChunk('single') config.optimization.runtimeChunk("single");
}) });
} },
} };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!