Skip to content

Commit 7d0b745

Browse files
committed
feat: 解决自动导入页面的 bug
1 parent b164c27 commit 7d0b745

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"vuex": "^3.1.3"
1717
},
1818
"devDependencies": {
19+
"@d2-projects/vue-filename-injector": "^1.1.1",
1920
"@vue/cli-plugin-babel": "^4.3.0",
2021
"@vue/cli-plugin-eslint": "^4.3.0",
2122
"@vue/cli-plugin-router": "^4.3.0",

src/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const views = []
1010
const vueFiles = require.context('@/views', true, /page\.vue$/)
1111
vueFiles.keys().forEach(key => {
1212
const component = vueFiles(key).default
13-
const routePath = path.dirname(component.__file).replace(/^src\/views\//, '')
13+
const routePath = path.dirname(component.__source).replace(/^src\/views\//, '')
1414
const routeName = routePath.replace(path.sep, '-')
1515
views.push({
1616
name: routeName,

vue.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const VueFilenameInjector = require('@d2-projects/vue-filename-injector')
2+
13
const publicPath = process.env.VUE_APP_PUBLIC_PATH || '/'
24

35
module.exports = {
@@ -11,5 +13,10 @@ module.exports = {
1113
prependData: `@import '~@/assets/style/public.scss';`
1214
}
1315
}
16+
},
17+
chainWebpack: config => {
18+
VueFilenameInjector(config, {
19+
propName: '__source'
20+
})
1421
}
1522
}

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,13 @@
824824
resolve-from "^5.0.0"
825825
resolve-global "^1.0.0"
826826

827+
"@d2-projects/vue-filename-injector@^1.1.1":
828+
version "1.1.1"
829+
resolved "https://registry.yarnpkg.com/@d2-projects/vue-filename-injector/-/vue-filename-injector-1.1.1.tgz#699ce81a17d6b3b2fbacf62fa76d37f57f939f89"
830+
integrity sha512-zR93EYjtk0pqcZGWTWZKtpB2HpHnmt7E4ysl8owUsD+pIyNK+2bXvhEiKGTgpnHFm+c/LzNdBrTUaQUgAKRLrQ==
831+
dependencies:
832+
loader-utils "^1.4.0"
833+
827834
"@hapi/address@2.x.x":
828835
version "2.1.4"
829836
resolved "https://registry.npm.taobao.org/@hapi/address/download/@hapi/address-2.1.4.tgz#5d67ed43f3fd41a69d4b9ff7b56e7c0d1d0a81e5"

0 commit comments

Comments
 (0)