Skip to content

Commit

Permalink
fix(remoteEntry): fix the url error of remoteEntry.json and the error…
Browse files Browse the repository at this point in the history
… of the external library import
  • Loading branch information
He110te4m committed Jul 17, 2023
1 parent b93dfad commit de344fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/dev-externals-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export const devExternalsMixin = {
},
configResolved(resolvedConfig) {
const VALID_ID_PREFIX = `/@id/`;
const reg = new RegExp(`${VALID_ID_PREFIX}(${federationBuilder.externals.join('|')})`, 'g');
const reg = new RegExp(
`(?<quote>["\'])[^\'"]*?${VALID_ID_PREFIX}(${federationBuilder.externals.join(
'|'
)})\\k<quote>`,
'g'
);
resolvedConfig.plugins.push({
name: 'vite-plugin-ignore-static-import-replace-idprefix',
transform: (code) => (reg.test(code) ? code.replace(reg, (m, s1) => s1) : code),
transform: (code) =>
reg.test(code) ? code.replace(reg, (_m, quote, libName) => quote + libName + quote) : code,
});
},
resolveId: (id) => {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ const configureDevServer = async (server: ViteDevServer, params: BuildHelperPara

const op = params.options;
const dist = path.join(op.workspaceRoot, op.outputPath);
server.middlewares.use(serveFromDist(dist));
server.middlewares.use(serveFromDist(dist, server.config.base));
};

const serveFromDist = (dist: string): Connect.NextHandleFunction => {
const serveFromDist = (dist: string, baseUrl: string): Connect.NextHandleFunction => {
return (req, res, next) => {
if (!req.url || req.url.endsWith('/index.html')) {
next();
return;
}

const file = path.join(dist, req.url);
const file = path.join(dist, req.url.replace(baseUrl, ''));
if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', mime.lookup(req.url));
Expand Down

0 comments on commit de344fd

Please sign in to comment.