F-loat / mpvue-entry

⛓️ 集中式页面配置,统一构建入口,支持新增页面热更新
MIT License
353 stars 56 forks source link

fix: 修复 pages path 为父目录或 Windows 路径时生成 entryName 错误 #104

Closed Cweili closed 5 years ago

Cweili commented 5 years ago

pages path 为父目录时,生成的 entry file 就不在 entry 目录中了

codecov[bot] commented 5 years ago

Codecov Report

Merging #104 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #104   +/-   ##
=======================================
  Coverage   60.92%   60.92%           
=======================================
  Files          12       12           
  Lines         302      302           
  Branches       58       58           
=======================================
  Hits          184      184           
  Misses        118      118
Impacted Files Coverage Δ
lib/parser/pages.js 76.47% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 595d379...62a6310. Read the comment docs.

F-loat commented 5 years ago

举例说明下这个的作用?

Cweili commented 5 years ago

@F-loat 我们的工程目录结构,是把小程序通用的那部分 build、config、共用的组件等放在了一个 git submodule 里,然后在不同的小程序工程中引用,这样 pages 相对路径就在父级目录里了。

/
    src
         pages

    framework
         build
         config
         src
              app.vue
              main.js
// app.js
const path = require('path');
const resolve = (...paths) => path.resolve('../../src', ...paths);

module.exports = {
  pages: [
    {
      route: 'pages/index/index',
      path: resolve('pages/index/index') // Windows 下 -> ..\\..\\src\\pages\\index\\index
    },
    ...
  ],
  ...
};

之前的代码用这样的配置,会把 entry 生成到我的源码目录(/src)下。

在源码目录里同时会出现 index.jsindex.vue,在 index.js 中是 import '@..\\..\\src\\pages\\index\\index' 导致 webpack 认为 import 自身(.js.vue 同时存在先找 .js)造成编译错误。

F-loat commented 5 years ago

好的