-
Notifications
You must be signed in to change notification settings - Fork 137
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 Prototype Vite Packager #759
Conversation
cc532b3
to
b6487fe
Compare
b6487fe
to
15edc25
Compare
Just for updates: locally, I'm working on a testing strategy. My plan right now is to introduce a I'm currently working on this in the Obviously I have not come across this with simpler apps that are successfully packaged using Vite. Maybe it's an issue with that specific module? That test app is using a version of the addon that claims to only support up to Ember 3.8, and the app is running Ember 3.13. It's probably not that, but I'm not sure why this particular module would be having an issue like this. This package also seems to hook up a custom Babel 6 plugin, but |
The problem in vertical-collection is probably that it opts out of the standard babel handling and does its own thing instead. This results in embroider seeing AMD instead of ES modules. That actually works under webpack because webpack understands AMD, but it's a bad pattern we'd like people to stop using. You can workaround by writing a compat adapter for vertical-collection that disables their custom treeForAddon entirely. Here's an example that does a similar thing. Regarding testing, we have new better test infrastructure implemented within ember-auto-import and @thoov is working on making it available in embroider too. It will make it much easier to write tests that need to run under multiple different packagers. See #756. |
Awesome, thanks for the context @ef4! I'll keep an eye on that PR and see if I can do something to get That whole package is pretty confusing... it appears that locally, |
That did the trick for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Current status: I figured out how to get the Current problems:
I have noticed that Babel is opting out of transforming some files produces by the CommonJS plugin; these files have a Example of what the file path looks like for a
|
15edc25
to
974181d
Compare
I pushed up my current state of things, just for reference by anyone following along at home. Spent another hour trying to figure out what is going on with those couple of modules that are not handled correctly... not sure what exactly it is just yet. One thing I'm wondering, with the |
Status update:
|
Alright, so it doesn't seem like the issue is the lint package after all. When handing multiple HTML files off to Vite for building, to seems to create a single This module includes some JavaScript that is inappropriate for one reason or another. For example:
If I tweak the Vite packager so that it only bundles the app's I'm not sure exactly where the fault here lies. The bundling is performed by Rollup, and I'm surprised that it's creating a set of JS bundles where the app JS includes files that it does not in fact need on it's own. I'm going to dig further into how Rollup is supposed to handle multiple HTML entry points, as I think that should reveal the remaining issue with this packager. |
hey @alexlafroscia, thank you so much for your work. This is going to be, imho, a huge win for embroider. I found this, which may be helpful for the multiple entry point issue you're running into -> https://github.com/rollup/plugins/tree/master/packages/multi-entry |
What's the status of this PR? I want to try to move an application to vite/embroider and wanted to see if there was a pressing issue stopping this from being merge. Thank you. |
Hey all -- sorry I've been MIA for this PR for a while. I've been busy and once I got my head out of this problem space, it was kind of hard to come back into it again! I'm going to try to get back into this again now that the testing situation seems to have matured. As for current status, I have the PR rebased and updated so that it should be merge-able once there's a story around testing. Determining how tests will work is what I'm working on now -- I'll be looking at how the Webpack packager works to determine what needs to be done to test the Vite packager as well! |
974181d
to
392232c
Compare
So I'm seeing a lot of different apps/addon in this directory, all of which are hard-coded against the Webpack packager It seems like we'll want to expand the testing matrix that I would love some guidance from someone in-the-know (@ef4 @rwjblue @thoov, maybe others?) on how to build the groundwork for different packagers as well. What I'm imagining is some repo-specific testing utility that detects the installed packager and returns the instance and configuration to use. Something like... this, maybe? // ember-cli-build.js
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { getPackagerFromEnvironment } = require('@embroider/test-support');
module.exports = function (defaults) {
let app = new EmberApp(defaults, {
// Add options here
});
const { packager, requiredConfig } = getPackagerFromEnvironment();
return require('@embroider/compat').compatBuild(app, packager, {
...requiredConfig,
skipBabel: [
{
package: 'qunit',
},
],
});
}; Where My example shows a thought on how configuration to the packager could be provided, too, but I have no idea if that's necessary or a good idea; we just have room in this faux API for that kind of functionality, should it be necessary. If we like this idea, I could start a separate, prerequisite PR that performs the refactoring required to get the current test suite working this way for the Webpack packager, then build on that to add Vite to this mix for this PR. I'm very open to other ideas on how we can dynamically determine the packager to build against for each test package in this repo as well! We just need to come up with some way to convert the currently-hard-coded use of the Webpack packager into some kind of dynamic locating, and it seems like we'd want to build on top of the current |
I think As far as expanding the test matrix goes, we should do it selectively. A lot of tests are covering things in embroider/compat or embroider/core that don't depend on the packager, so we should avoid duplicating all that coverage. Also, I don't think we want vite vs webpack to multiply against all the different supported ember versions. |
Sounds good @ef4 -- I will try to put something separate together this week that updates some of the tests to load the package from the environment, and then we can work from there on getting the Vite packager tested using that! |
This utility function allows an app to load an Embroider packager dynamically from their dependencies. This is useful for testing, where we want to run the same tests against different packagers to verify that the packagers actually work. Tastes great with `scenario-tester`!
The PR linked above implements the dynamic-packager-loading-for-tests behavior that we discussed here last week. It seems like it works! Just to keep things moving here, I'll rebase this PR on that branch so we can actually see if the Vite tests would pass under that kind of infrastructure. |
392232c
to
e90f448
Compare
I wasn't sure how to pull this off I tried to use the export function supportMatrix(scenarios: Scenarios) {
return scenarios
.expand({
lts_3_16,
lts_3_20,
lts_3_24,
release,
})
.expand({
packager_vite,
packager_webpack,
})
.skip('lts_3_16-packager_vite');
} but that didn't work; I could skip all of I checked the |
Whew! Adding Vite to all of the |
e90f448
to
2c9462c
Compare
Maybe this is useful? https://github.com/unjs/unplugin |
Anything I can do to help get things moving again? |
I made this demo here: https://github.com/NullVoxPopuli/vite-demo everything builds fine, and ember s starts fine (but taking 20s??)
|
@alexlafroscia is there anything that the community can help with to get this feature out the door? |
Just wanted to throw another comment here - @alexlafroscia - this looks really interesting, and possibly intersects with some work we're doing. Let us know if there's anything we can do to help get this across the finish line. |
I asked @alexlafroscia if he could give me any pointers on how to proceed with this but he doesn't know because it's been a while and doesn't have the time to work on it anymore, maybe a new PR is in order?? I got it to build my large test app with embroider 1.8.0 and here are my findings. templateCompilerPlugin({
templateCompilerFile: join(this.pathToVanillaApp, meta['template-compiler'].filename),
variant: this.variant,
}),
It doesn't copy anything from outside the Most require imports are not being transpiled (at least on my large test app), as mentioned above, no idea how to fix that one. |
Hey all -- I think I'm going to close this PR and let someone else try to make headway on this. If you can use any of this code to make a Vite packager, please feel free to do so! As @x8BitRain mentioned, this isn't something I can really move forward with; it's been too long since I wrote the initial work, and I would feel an obligation to maintain this integration going forward that I would not realistically be able to commit to. Sorry to back out of this PR having opened it, but I work on very little OSS these days as it's no longer a part of my job responsibilities. I hope someone else can make something like this work; Vite is awesome, and I would love to someday see the Ember community in a position to embrace it! |
Linking more radical way to use |
@lifeart Interesting! Do you know if @ef4 has seen this? As I understood it the general idea with Embroider was to make it easy to use (and outsource) the build logic to popular JS build tools, and avoid building a custom pipeline for Ember (as much as possible). Seems like your demo repo is in the same spirit! |
Yes I've seen it. It's the same as several other demos we have shown with ember and vite. Embroider automatically generates all the messy compatibility code that this demo writes by hand. The demo also defeats code splitting because it registers everything in advance. Recent embroider versions actually skip the registry entirely in the vast majority of cases, because we can use ember's newer template lexical scope. We expect very soon to be moving people toward inverting the flow of control so that you directly run the tool in question (vite or webpack or rollup) and it has plugins that invoke backward-compatibility behaviors, as opposed to running ember-cli and having the broccoli pipeline invoke the other packager. |
@ef4 code splitting concerns little bit incorrect: lazy routes defined here, but I agree, if component is already registered in global scope, it not gonna be splitted automatically. But, it's possible to have independent bundles of global registered components per route (require manual registry import & initialization on route level) I would not call part of code as messy compatibility code for this reasons:
|
I've been really interested in Vite lately, and wanted to see what it would be like to write a packager for Vite!
I started working on this in a separate repo: https://github.com/alexlafroscia/embroider-vite
Now that it seems like the basics have been worked out here, I decided to open a PR with a cleaned-up version that might be worth landing up-stream. I'll probably keep hacking on it in that repo as well and upstream improvements here as I go!
Packages
@embroider/rollup-plugin-hbs
I borrowed the approach for the Webpack loader to create this. Vite's documentation recommends adopting the
rollup-plugin
naming if you are not using any Vite-specific functionality in the plugin; Vite plugins are super-sets of Rollup plugins, so we can actually create a Rollup plugin here and it fits perfectly into Vite too! Less to do down the road if someone ever wants a standalone Rollup packager or something.@embroider/vite
I know that @ef4 mentioned he was working on one a while ago over in #717, but I figured it would still be worth offering up what I had to see if we can land a "real" version of this!
Right now the following is working
@rollup/plugin-babel
to Vite)@embroider/rollup-plugin-hbs
to Vite)commonjs
imports that are created by theimportSync
macroCurrently, the following are not working
require
imports are not being transpiledAnd the following need to be implemented in some way
I think there's a fair amount of overlap in what both Vite and Webpack need Embroider to do for the asset pass-through; I think there's likely some common functionality that could be extracted and shared! Maybe we can talk through what that would look like, as I would love to contribute those changes!
With the current state of this PR, it'll boot an app just fine that uses this as the packager instead of Webpack. It's not nearly as fast as I would like; I need to figure out if/how we can take advantage of running the Vite dev server rather than doing a full "build" on every file change. It would be really interesting if we could come up with a different paradigm for running a packager in "dev" mode, where rather than the packager's
build
being called for every file change, the dev server would just handle the file changes itself. Maybe something like that would be RFC-worthy?Relationship to ESBuild
I think between ESBuild, Rollup and Vite, it would make the most sense to create a first-party Vite plugin for Embroider. It's more appropriate for packaging applications, rather than libraries, and itself uses ESBuild or Rollup internally (or at least, supports Rollup plugins). Very little is needed in the
@embroider/vite
package to connect everything together!What I'm Looking for Feedback On