From 7340d6ac2ba2720fa8014a9fecb9a91da08ce9ff Mon Sep 17 00:00:00 2001 From: bucai <1450941858@qq.com> Date: Fri, 26 Nov 2021 17:55:12 +0800 Subject: [PATCH] fix: docs webpack config --- package.json | 3 ++ website/md-loader/index.js | 12 +++--- website/webpack.config.js | 10 +++-- yarn.lock | 83 +++++++++++++++++++++++++++++++++++++- 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 206037d..72b9144 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-typescript": "^8.2.5", "@types/jest": "^27.0.1", + "@types/nprogress": "^0.2.0", "@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/parser": "^5.4.0", "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", @@ -83,6 +84,7 @@ "eslint-plugin-vue": "^7.0.0-beta.4", "file-loader": "^6.2.0", "flush-promises": "^1.0.2", + "friendly-errors-webpack-plugin": "^1.7.0", "highlight.js": "^11.2.0", "html-webpack-plugin": "^5.3.2", "husky": "^7.0.4", @@ -93,6 +95,7 @@ "markdown-it-chain": "^1.3.0", "markdown-it-container": "^3.0.0", "mini-css-extract-plugin": "^2.2.0", + "nprogress": "^0.2.0", "ora": "5.4.1", "prettier": "^2.4.1", "progress-bar-webpack-plugin": "^2.1.0", diff --git a/website/md-loader/index.js b/website/md-loader/index.js index 6644ebd..01a48c9 100644 --- a/website/md-loader/index.js +++ b/website/md-loader/index.js @@ -4,7 +4,7 @@ const { stripTemplate, genInlineComponentText, } = require('./util') -const babelConfig = require('../../babel.config') +// const babelConfig = require('../../babel.config') const babel = require('@babel/core') const md = require('./config') @@ -15,7 +15,7 @@ module.exports = function (source) { const startTagLen = startTag.length const endTag = ':element-demo-->' const endTagLen = endTag.length - let componenetsString = '' + let componentsString = '' let id = 0 // demo 的 id let output = [] // 输出的内容 let start = 0 // 字符串开始位置 @@ -37,8 +37,8 @@ module.exports = function (source) { const demoComponentName = `element-demo-${id}` let demoComponentContent = genInlineComponentText(html, newScript, demoComponentName) - output.push(``) - componenetsString += `${JSON.stringify(demoComponentName)}: ${demoComponentContent},` + output.push(``) + componentsString += `${JSON.stringify(demoComponentName)}: ${demoComponentContent},` // 重新计算下一次的位置 id++ start = commentEnd + endTagLen @@ -50,14 +50,14 @@ module.exports = function (source) { // todo: 优化这段逻辑 let pageScript = '' - if (componenetsString) { + if (componentsString) { pageScript = `` diff --git a/website/webpack.config.js b/website/webpack.config.js index 5dd93e9..17e4272 100644 --- a/website/webpack.config.js +++ b/website/webpack.config.js @@ -2,7 +2,7 @@ * @Author: bucai<1450941858@qq.com> * @Date: 2021-08-17 15:14:57 * @LastEditors: bucai<1450941858@qq.com> - * @LastEditTime: 2021-11-23 13:29:58 + * @LastEditTime: 2021-11-26 17:45:01 * @Description: */ /* eslint-disable @typescript-eslint/no-var-requires */ @@ -14,10 +14,11 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin') const CssMinimizerPlugin = require('css-minimizer-webpack-plugin') const TerserPlugin = require('terser-webpack-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin') +const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin') +const ProgressBarPlugin = require('progress-bar-webpack-plugin') // 安装成本太高了 // const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin') -const ProgressBarPlugin = require('progress-bar-webpack-plugin') // const SpeedMeasurePlugin = require('speed-measure-webpack-plugin') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin @@ -153,16 +154,18 @@ const config = { 'vue-router': 'VueRouter', 'element-plus': 'ElementPlus', 'highlight.js': 'hljs', + 'nprogress': 'NProgress', }, devServer: { inline: true, // 如果使用 vue 的生产环境构建包,无法启用 hmr // 因为生产环境下 vue 没有注入 hmr 必须的 __VUE_HMR_RUNTIME__ api hot: !isVueProd, - stats: 'minimal', + // stats: 'minimal', publicPath: '/', contentBase: __dirname, overlay: true, + // stats: "", }, optimization: { minimize: isProd, @@ -259,6 +262,7 @@ if (isProd) { }) } else { config.plugins.push(new webpack.HotModuleReplacementPlugin()) + config.plugins.push(new FriendlyErrorsWebpackPlugin()) cssRule.use.unshift('style-loader') } if (process.env.NODE_ANALYZER_ENV) { diff --git a/yarn.lock b/yarn.lock index e5ac7d8..1bc28d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1503,6 +1503,11 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw== +"@types/nprogress@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@types/nprogress/-/nprogress-0.2.0.tgz#86c593682d4199212a0509cc3c4d562bbbd6e45f" + integrity sha512-1cYJrqq9GezNFPsWTZpFut/d4CjpZqA0vhqDUPFWYKF1oIyBz5qnoYMzR+0C/T96t3ebLAC1SSnwrVOm5/j74A== + "@types/prettier@^1.0.0 || ^2.0.0", "@types/prettier@^2.0.0": version "2.4.2" resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.2.tgz#4c62fae93eb479660c3bd93f9d24d561597a8281" @@ -2327,6 +2332,11 @@ ansi-regex@^2.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= + ansi-regex@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" @@ -2337,6 +2347,11 @@ ansi-regex@^5.0.0, ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== +ansi-styles@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4= + ansi-styles@^3.2.0, ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -3069,6 +3084,17 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= +chalk@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + integrity sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg= + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" @@ -4195,6 +4221,13 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +error-stack-parser@^2.0.0: + version "2.0.6" + resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.6.tgz#5a99a707bd7a4c58a797902d48d82803ede6aad8" + integrity sha512-d51brTeqC+BHlwF0BhPtcYgF5nlzf9ZZ0ZIUQNZpc9ZB9qw5IJ2diTrBY9jlCJkTLITYPjmiX6OWCwH+fuyNgQ== + dependencies: + stackframe "^1.1.1" + es-module-lexer@^0.9.0: version "0.9.3" resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" @@ -4215,7 +4248,7 @@ escape-html@~1.0.3: resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= -escape-string-regexp@^1.0.5: +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= @@ -4939,6 +4972,15 @@ fresh@0.5.2: resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= +friendly-errors-webpack-plugin@^1.7.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-1.7.0.tgz#efc86cbb816224565861a1be7a9d84d0aafea136" + integrity sha512-K27M3VK30wVoOarP651zDmb93R9zF28usW4ocaK3mfQeIEI5BPht/EzZs5E8QLLwbLRJQMwscAjDxYPb1FuNiw== + dependencies: + chalk "^1.1.3" + error-stack-parser "^2.0.0" + string-width "^2.0.0" + from2@^2.1.0: version "2.3.0" resolved "https://registry.yarnpkg.com/from2/-/from2-2.3.0.tgz#8bfb5502bde4a4d36cfdeea007fcca21d7e382af" @@ -5198,6 +5240,13 @@ har-validator@~5.1.3: ajv "^6.12.3" har-schema "^2.0.0" +has-ansi@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + integrity sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE= + dependencies: + ansi-regex "^2.0.0" + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -7317,6 +7366,11 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" +nprogress@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1" + integrity sha1-y480xTIT2JVyP8urkH6UIq28r7E= + nth-check@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.0.1.tgz#2efe162f5c3da06a28959fbd3db75dbeea9f0fc2" @@ -9313,6 +9367,11 @@ stack-utils@^2.0.2: dependencies: escape-string-regexp "^2.0.0" +stackframe@^1.1.1: + version "1.2.0" + resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.2.0.tgz#52429492d63c62eb989804c11552e3d22e779303" + integrity sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA== + static-extend@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" @@ -9378,6 +9437,14 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" +string-width@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + string-width@^3.0.0, string-width@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" @@ -9410,13 +9477,20 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -strip-ansi@^3.0.1: +strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" integrity sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8= dependencies: ansi-regex "^2.0.0" +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= + dependencies: + ansi-regex "^3.0.0" + strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" @@ -9484,6 +9558,11 @@ stylehacks@^5.0.1: browserslist "^4.16.0" postcss-selector-parser "^6.0.4" +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc= + supports-color@^5.3.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"