Skip to content

Commit

Permalink
fix: loading error when running nocobase under subpath (#5924)
Browse files Browse the repository at this point in the history
* fix: plugin dynamic import should use relative path

* fix: output public path

* fix(buildPlugin): update public path handling and add custom public path plugin
  • Loading branch information
gchust authored Dec 24, 2024
1 parent 55c6a5d commit 1499cae
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions packages/core/build/src/buildPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1499cae

Please sign in to comment.