vue-vben-admin micro-app支持

eeq64g8w  于 2023-02-04  发布在  其他
关注(0)|答案(3)|浏览(438)

micro-app微前端框架,在本地可以调试通,但是在打包的时候会报错
TypeError [ERR_INVALID_URL]: Invalid URL: /assets/
at new NodeError (node:internal/errors:329:5)
at onParseError (node:internal/url:537:9)
at new URL (node:internal/url:613:5)
at new URL (node:internal/url:610:22)
at /Users/jimei/work/algorithm-evaluation/vite.config.ts:706:40
at String.replace ()
at Object.writeBundle (/Users/jimei/work/algorithm-evaluation/vite.config.ts:705:39)
at /Users/jimei/work/algorithm-evaluation/node_modules/rollup/dist/shared/rollup.js:22870:37
at async Promise.all (index 1)
at async /Users/jimei/work/algorithm-evaluation/node_modules/rollup/dist/shared/rollup.js:23741:13
at async catchUnfinishedHookActions (/Users/jimei/work/algorithm-evaluation/node_modules/rollup/dist/shared/rollup.js:23174:20)
at async doBuild (/Users/jimei/work/algorithm-evaluation/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41701:20)
at async build (/Users/jimei/work/algorithm-evaluation/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41527:16)
at async CAC. (/Users/jimei/work/algorithm-evaluation/node_modules/vite/dist/node/cli.js:738:9)

找到位置是因为在build/vite/index.ts中添加了:
vitePlugins.push(
(function () {
  let basePath = '';
  return {
    name: 'hercules',
    apply: 'build',
    configResolved(config) {
      basePath = `${config.base}${config.build.assetsDir}/`;
    },
    writeBundle(options, bundle) {
      for (const chunkName in bundle) {
        if (Object.prototype.hasOwnProperty.call(bundle, chunkName)) {
          const chunk = bundle[chunkName];
          if (chunk.fileName && chunk.fileName.endsWith('.js')) {
            chunk.code = chunk.code.replace(/(from|import\()(\s*['"])(\.\.?\/)/g, (all, $1, $2, $3) => {
              return all.replace($3, new URL($3, basePath))
            })
            const fullPath = join(options.dir, chunk.fileName)
            writeFileSync(fullPath, chunk.code)
          }
        }
      }
    },
  };
})() as any,

);

帮忙看一下这种是什么问题

ct2axkht

ct2axkht1#

可否提供一下重现代码或者最小化项目?

dkqlctbz

dkqlctbz2#

兄弟解决了吗?

093gszye

093gszye3#

兄弟解决了吗?

你们应用了吗

相关问题