Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent user plugin order #465

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-monkeys-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

Use same user plugin ordering in dev and production mode
8 changes: 5 additions & 3 deletions packages/wmr/src/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ export async function bundleProd({
input.push('./' + pathToPosix(relative(root, abs)));
});

// Plugins are pre-sorted
const split = plugins.findIndex(p => p.enforce !== 'post');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait this doesn't make sense. The condition should be inverted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be !== 'pre' - the index that marks the end of the "pre" items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the first index of null/'normal'/'post'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo normal plugins should be moved to the start too. You'll usually want to intercept stuff before we'd internal plugins. It was one of the key learnings in vite


const bundle = await rollup.rollup({
input,
perf: !!profile,
preserveEntrySignatures: 'allow-extension',
manualChunks: npmChunks ? extractNpmChunks : undefined,
plugins: [
...plugins.filter(p => p.enforce === 'pre'),
...plugins.filter(p => p.enforce === 'normal' || !p.enforce),
...plugins.slice(0, split),
nodeBuiltinsPlugin({ production: true }),
externalUrlsPlugin(),
sucrasePlugin({
Expand Down Expand Up @@ -128,7 +130,7 @@ export async function bundleProd({
npmPlugin({ external: false }),
urlPlugin({}),
jsonPlugin(),
...plugins.filter(p => p.enforce === 'post'),
...plugins.slice(split),
bundlePlugin({ cwd }),
optimizeGraphPlugin({ publicPath }),
minify && minifyCssPlugin({ sourcemap }),
Expand Down
3 changes: 2 additions & 1 deletion packages/wmr/src/wmr-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export default function wmrMiddleware({

root = root || cwd;

const split = plugins.findIndex(p => p.enforce !== 'pre');
// Plugins are pre-sorted
const split = plugins.findIndex(p => p.enforce !== 'post');
const NonRollup = createPluginContainer(
[
...plugins.slice(0, split),
Expand Down