soybeanjs / vite-plugin-vue-page-route

vite插件,根据页面文件生成路由声明文件
13 stars 10 forks source link

最新版报错 #4

Open AnyFork opened 1 year ago

AnyFork commented 1 year ago

配置如下:

 pageRoute({
        pageDir: "src/views",
        pageGlobs: ["**/index.{vue,tsx,jsx}", "!**/components/**"],
        routeDts: "src/types/page-route.d.ts",
        routeModuleDir: "src/router/module",
        routeModuleExt: "ts",
        routeModuleType: "AuthRoute.Route",
        /**
         * @example _builtin_login => login
         */
        routeNameTansformer: (name) =>
          name.replace(/^_([a-zA-Z]|[0-9]|$)+_*/, ""),
        /**
         * 路由懒加载
         * @param name 路由名称
         * @example
         * - 直接导入
         * ```ts
         * import Home from './views/home/index.vue';
         * ```
         * - 懒加载导入
         * ```ts
         * const Home = import('./views/home/index.vue');
         * ```
         */
        lazyImport: (_name) => true, // 默认
        /**
         * 是否生成路由模块
         * @param name 未转换过的路由名称(没有调用函数routeNameTansformer)
         * @returns 是否生成路由模块的代码
         */
        onRouteModuleGenerate: (name) => !name.includes("_builtin"),
      })
    ],

启动报错

PS G:\anyfork-common-admin\vue-anyfork-admin> pnpm dev

> vue-anyfork-admin@0.0.0 dev G:\anyfork-common-admin\vue-anyfork-admin
> vite

failed to load config from G:\anyfork-common-admin\vue-anyfork-admin\vite.config.ts
error when starting dev server:
file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+@soybeanjs+vite-plugin-vue-page-route@0.0.7/node_modules/@soybeanjs/vite-plugin-vue-page-route/dist/index.mjs:49
import { isMatch } from "micromatch";
         ^^^^^^^
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'micromatch';
const { isMatch } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async loadConfigFromBundledFile (file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+vite@4.4.4_@types+node@20.4.2/node_modules/vite/dist/node/chunks/dep-abb4f102.js:66128:21)
    at async loadConfigFromFile (file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+vite@4.4.4_@types+node@20.4.2/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65979:28)
    at async resolveConfig (file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+vite@4.4.4_@types+node@20.4.2/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65575:28)
    at async _createServer (file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+vite@4.4.4_@types+node@20.4.2/node_modules/vite/dist/node/chunks/dep-abb4f102.js:64846:20)
    at async CAC.<anonymous> (file:///G:/anyfork-common-admin/vue-anyfork-admin/node_modules/.pnpm/registry.npmmirror.com+vite@4.4.4_@types+node@20.4.2/node_modules/vite/dist/node/cli.js:743:24)
 ELIFECYCLE  Command failed with exit code 1.
honghuangdc commented 1 year ago

ES module暂时有问题

honghuangdc commented 1 year ago

请先用 commonjs模式运行

honghuangdc commented 1 year ago

路由插件 elegant-router 会代替该插件,敬请期待