chore: better parity for initing admin routes between dev and build (#3074)
This commit is contained in:
@@ -19,12 +19,12 @@ export const getDevConfig = (payloadConfig: SanitizedConfig): Configuration => {
|
||||
entry: {
|
||||
...baseConfig.entry,
|
||||
main: [
|
||||
require.resolve('webpack-hot-middleware/client'),
|
||||
`webpack-hot-middleware/client?path=${payloadConfig.routes.admin}/__webpack_hmr`,
|
||||
...(baseConfig.entry.main as string[]),
|
||||
],
|
||||
},
|
||||
output: {
|
||||
publicPath: payloadConfig.routes.admin,
|
||||
publicPath: `${payloadConfig.routes.admin}/`,
|
||||
path: '/',
|
||||
filename: '[name].js',
|
||||
},
|
||||
|
||||
@@ -11,14 +11,14 @@ const router = express.Router();
|
||||
|
||||
type DevAdminType = (options: { payload: Payload }) => Promise<PayloadHandler>;
|
||||
export const devAdmin: DevAdminType = async ({ payload }) => {
|
||||
payload.express.use(payload.config.routes.admin, history());
|
||||
router.use(history());
|
||||
|
||||
try {
|
||||
const webpackConfig = getDevConfig(payload.config);
|
||||
const compiler = webpack(webpackConfig);
|
||||
|
||||
router.use(webpackDevMiddleware(compiler, {
|
||||
publicPath: webpackConfig.output.publicPath as string,
|
||||
publicPath: '/',
|
||||
}));
|
||||
|
||||
router.use(webpackHotMiddleware(compiler));
|
||||
|
||||
@@ -5,7 +5,7 @@ async function initAdmin(ctx: Payload): Promise<void> {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
ctx.express.use(ctx.config.routes.admin, await ctx.config.admin.bundler.serve(ctx));
|
||||
} else {
|
||||
ctx.express.use(await ctx.config.admin.bundler.dev(ctx));
|
||||
ctx.express.use(ctx.config.routes.admin, await ctx.config.admin.bundler.dev(ctx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user