-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
3.1.0-pre.0 bundle size regression with rollup #6687
Comments
My current workaround is just to strip these {
transform(code, id) {
const magicString = new MagicString(code);
const ast = this.parse(code);
walk(ast, {
enter: function (node) {
if (
node.type === "ImportDeclaration" &&
node.specifiers.length === 0 &&
node.source.value !== "symbol-observable"
) {
magicString.remove(node.start, node.end);
}
},
});
return {
code: magicString.toString(),
};
},
}; |
This partially reverts commit 627bd1b from PR #6656. PR #6656 removed a function called `prepareESM`, which was no longer needed for the sake of running `rollup-plugin-invariant`, but which had another benefit: Rollup would replace imports/exports like // Example exports from ./dist/index.js: export * from './core' export * from './react' with their fully-expanded (and file-extensioned) equivalents: ... export { makeVar } from './cache/inmemory/reactiveVars.js'; export { defaultDataIdFromObject } from './cache/inmemory/policies.js'; export { InMemoryCache } from './cache/inmemory/inMemoryCache.js'; export { ApolloClient } from './core/ApolloClient.js'; ... Although this may look like more code, it effectively saves the bundler/browser work by reducing indirection, and including the .js file extensions makes this code a little more browser- and Rollup-friendly (that is, you shouldn't have to use @rollup/plugin-node-resolve to bundle @apollo/client with Rollup). The expanded imports/exports are also closer to the ESM code shipped with @apollo/[email protected], so restoring this behavior helps with the goal of keeping the changes in #6656 backwards-compatible for v3.1.0. Note that the CommonJS bundles used by Node.js are built before this step, so this expansion of imports does not affect Node.js.
@henryqdineen This is great feedback, and really validates the decision to publish I was uneasy with those specifier-less imports too, and couldn't find a combination of Rollup options to prevent them. I think they have something to do with import hoisting, which is supposedly disabled when In any case, I am planning to replace |
Thanks! Feel free to reach out if you need help testing out alternate solutions. |
@henryqdineen Give |
Thanks @benjamn! Nice solution in #6694. I just checked it out
Instead we have:
And in
My assumption is that rollup is considering stuff like |
I noticed one other small regression from In
In 3.1.0-pre
|
@henryqdineen Do you think it would help to replace import gql from 'graphql-tag';
export var resetCaches = gql.resetCaches, disableFragmentWarnings = gql.disableFragmentWarnings, enableExperimentalFragmentVariables = gql.enableExperimentalFragmentVariables, disableExperimentalFragmentVariables = gql.disableExperimentalFragmentVariables;
export { gql }; with export { default as gql } from 'graphql-tag' or is it more a matter of declaring the |
#6687 (comment) Methods specific to the gql template tag should be accessed via the gql function, rather than mixed in with the exports of @apollo/client.
@benjamn I just tried it out by adding |
This will help tree-shaking when used with projects that have a dependency on `graphql-tag` (like `@apollo/client`). Reference: apollographql/apollo-client#6687
This will help tree-shaking when used with projects that have a dependency on `graphql-tag` (like `@apollo/client`). Reference: apollographql/apollo-client#6687
I know this is prerelease but I just want to give some feedback. This is the same as a comment I made in faa64b3#r40855898 but I created an issue for more visibility.
I tried out
3.1.0.pre.0
and we are seeing a bundle size regression in our rollup bundle. Here is a snippet fromdist/core/index.js
before and afterI don't think rollup is able to treeshake the
import
s with no specifiers. Please let me know if you need any more info if there are any workarounds.The text was updated successfully, but these errors were encountered: