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 Vite (again) #47
Use Vite (again) #47
Conversation
🦋 Changeset detectedLatest commit: 79b70ea The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Nice, good to get back to a single bundler 🎉
packages/core/src/package/bundle.ts
Outdated
...externals(config.root, format), | ||
enforce: 'pre', |
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.
Given that we own externals now, could the pre
just be rolled into the plugin, rather than having to spread here?
return { | ||
...plugin, | ||
name: `crackle:patched-${plugin.name}`, | ||
async buildStart(options) { |
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.
Once you start adding in async
s, I find this inline key function definition style really unclear that it's part of an object. Could we go with buildStart: async(options) => {
, etc?
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 agree, however changing the meaning of this
breaks the plugin so we can't use an arrow function. This
buildStart: async function (options) {}
gets ESLint-fixed to
async buildStart(options) {}
@@ -0,0 +1,6 @@ | |||
import { resolvePath } from 'mlly'; |
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 think the dep on mlly has been deleted in the package.json?
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 still there, just synced it to Vite's version so the diff is a bit more noisy.
This PR reintroduces Vite for bundling/packaging modules (
crackle package
) e.g. for precompiled Braid.The major changes are
bundle.ts
with Vite.mjs
extensionThis PR was tested in:
✅ Braid site with Crackle snapshot
✅
braid-site
fixture with Braid snapshot✅ Gotham candidate site with Crackle and Braid snapshots
Replaced Rollup with Vite
This one was pretty straightforward, as the hard work was already done by @mattcompiles and @benjervis before upgrading to Vite 3 (library mode was broken in Vite 3 so we had to go to Rollup). As of version 3.1.3, lib mode works again.
With the release of 3.2.0-beta.0, the fix for the SSR build issue is in so the legacy behaviour is no longer needed.
Added a Rollup plugin to resolve paths in ES Modules
The Rollup plugin combines the functionality of
rollup-plugin-node-externals
with thebuild.ssr
fix. Why is this needed? Two reasons:crackle build
) will fail if an import specifier refers to a file (import mapValues from 'lodash/mapValues'
) or a directory (import parse from 'autosuggest-highlight/parse
).So the Rollup plugin wraps
rollup-plugin-node-externals
androllup-plugin-node-externals
decide if an import is "external"lodash/mapValues
or@scope/something/other
)package.json
doesn't have an"exports"
keybuild.ssr
fixThis fix also removes the need to have a hardcoded list of exceptions for
crackle start
(related to this Vite issue).ESM bundles now use
.mjs
extensionPractically, there are two ways Node will treat a file as an ES Module:
.mjs
extension.js
extension withtype: "module"
in the nearest parentpackage.json
The implication (?) is that a file with a
.cjs
extension is always treated as a CommonJS module and a file with an.mjs
extension is always treated as an ES Module. So, if we save create bundles with.mjs
and.cjs
extensions we can publish packages that work in both environments 🎉.