-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add /esm build #791
Add /esm build #791
Conversation
These three files are used as entry points into the project, and we expect people to be importing them directly so they are at the top level for convenience. Because of this, they have not been getting run through Babel like the rest of the code here, so they were using older syntax. In this commit, I am moving these files into the src directory so they will be built into lib like the rest of the code here. In their place at the top level, I am creating some very light shims that simply bring in the built version of the module and re-export it if necessary. This gives us a couple of advantages. First, it makes more of our code consistent. Second, it makes it possible to produce two different kinds of builds, one for CommonJS consumers and another for ES modules consumers.
This ES modules build will make these modules smaller in the final bundles, since the way Babel compiles import to require is pretty verbose. Additionally, it will enable webpack to make some optimizations on the final bundle, including tree-shaking and scope hoisting (if enabled). These will improve bundle sizes and runtime performance. I considered adding a module field to the package.json to point to this version for folks who are able to use it, but I decided to wait on that for now since that is still pretty experimental. For now, consumers will need to use this either by importing from react-dates/esm directly or by using something like a webpack alias to use this version of the build. When working on this I originally kept the plugins array at the top level instead of repeating it for each env, but I ran into an issue that seemed related to ordering that caused babel-register in the compile CSS script to not apply the correct transformations. I was able to work around this by repeating the plugins for each env.
5424418
to
2124613
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
toLocalizedDateString: toLocalizedDateString, | ||
toMomentObject: toMomentObject, | ||
}; | ||
// eslint-disable-next-line import/no-unresolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is needed; it's fine if the linter requires the build process be ran first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly wanted to get rid of the error messages for myself when I was working in these files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run build
would have done that :-p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then npm run clean
would have broken it again :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not a blocker; but in general I think the warnings there are good; without them, you might unintentionally have a bad path. I don’t think it’s a good idea to optimize for the development case when it subtracts from production safety ¯\_(ツ)_/¯
@@ -1,4 +1,2 @@ | |||
// eslint-disable-next-line import/no-unresolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
} | ||
"presets": ["airbnb"], | ||
"plugins": [ | ||
"inline-react-svg", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super gnarly that we have to repeat these two plugins in every env due to ordering issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@lencioni @ljharb I think this change affected the gh-pages script which builds storybook. Specifically, I think it is using a babel environment that has no associated setting in the Here's the error I'm getting:
|
Yep seems likely. Do you know what env it uses?
|
I think it builds in production mode, but I'm unsure. EDIT: yup, it looks like it does Do we have to add another setting for that? |
In #791 I added an ESM build, but ended up breaking the production build for gh-pages. Storybook builds with NODE_ENV=production, so this should fix that problem.
In react-dates/react-dates#791 I added an ESM build, but ended up breaking the production build for gh-pages. Storybook builds with NODE_ENV=production, so this should fix that problem.
In react-dates/react-dates#791 I added an ESM build, but ended up breaking the production build for gh-pages. Storybook builds with NODE_ENV=production, so this should fix that problem.
This ES modules build will make these modules smaller in the final
bundles, since the way Babel compiles import to require is pretty
verbose. Additionally, it will enable webpack to make some optimizations
on the final bundle, including tree-shaking and scope hoisting (if
enabled). These will improve bundle sizes and runtime performance.
I considered adding a module field to the package.json to point to this
version for folks who are able to use it, but I decided to wait on that
for now since that is still pretty experimental.
For now, consumers will need to use this either by importing from
react-dates/esm directly or by using something like a webpack alias to
use this version of the build.
When working on this I originally kept the plugins array at the top
level instead of repeating it for each env, but I ran into an issue that
seemed related to ordering that caused babel-register in the compile CSS
script to not apply the correct transformations. I was able to work
around this by repeating the plugins for each env.
@airbnb/webinfra