fix: loading error when running nocobase under subpath (#5924)

* fix: plugin dynamic import should use relative path

* fix: output public path

* fix(buildPlugin): update public path handling and add custom public path plugin
This commit is contained in:
gchust 2024-12-24 14:11:23 +08:00 committed by GitHub
parent 55c6a5d577
commit 1499caea40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -339,7 +339,7 @@ export async function buildPluginClient(cwd: string, userConfig: UserConfig, sou
path: outDir,
filename: outputFileName,
chunkFilename: '[chunkhash].js',
publicPath: `/static/plugins/${packageJson.name}/dist/client/`,
publicPath: `auto`, // will be generated by the custom plugin
clean: true,
library: {
name: packageJson.name,
@ -467,14 +467,36 @@ export async function buildPluginClient(cwd: string, userConfig: UserConfig, sou
new rspack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
{
apply(compiler) {
compiler.hooks.compilation.tap('CustomPublicPathPlugin', (compilation) => {
compilation.hooks.runtimeModule.tap('CustomPublicPathPlugin', (module) => {
if (module.name === 'auto_public_path') {
// 处理所有可能的情况
module.source = {
source: `
__webpack_require__.p = (function() {
var publicPath = window['__nocobase_public_path__'] || '/';
// 确保路径以 / 结尾
if (!publicPath.endsWith('/')) {
publicPath += '/';
}
return publicPath + 'static/plugins/${packageJson.name}/dist/client/';
})();`
};
}
});
});
}
},
process.env.BUILD_ANALYZE === 'true' &&
new RsdoctorRspackPlugin({
// plugin options
// supports: {
// generateTileGraph: true,
// },
mode: 'brief',
}),
new RsdoctorRspackPlugin({
// plugin options
// supports: {
// generateTileGraph: true,
// },
mode: 'brief',
}),
].filter(Boolean),
node: {
global: true,