Skip to content

Commit 906b7ca

Browse files
authored
Merge pull request #150 from ember-engines/vite-documentation
add Embroider page and migration guide for 0.13.0
2 parents 589ed70 + bbcbe02 commit 906b7ca

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

tests/dummy/app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Router.map(function () {
3030
this.route('links');
3131

3232
this.route('migrations');
33+
this.route('embroider');
3334
this.route('deprecations');
3435
});
3536

tests/dummy/app/templates/docs.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<nav.item @label="What are Engines?" @route="docs.index" />
55
<nav.item @label="Installation" @route="docs.installation" />
66
<nav.item @label="Quickstart" @route="docs.quickstart" />
7+
<nav.item @label="Embroider" @route="docs.embroider" />
78
<nav.item @label="Deploying" @route="docs.deploying" />
89

910
<nav.section @label="Core Concepts" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Embroider Vite/Webpack
2+
3+
As of v0.13.0, Ember Engines is compatible with the new default Ember build system based on [Vite](https://vite.dev) and [Embroider](https://github.com/embroider-build/embroider). For your engines to work with Embroider you will need to make sure you are suing at least `ember-resolver@13.0.0` and you will need to update your `engine.js` entrypoint to pass `compatModules` to the resolver.
4+
5+
This method of using the `ember-resolver` with `compatModules` is usually not compatible with the Classic build system but `ember-engines` automatically provides a polyfill so that an engine that has been updated to work with Embroider+Vite will continue to work with a Classic app that is still using `ember-cli` for its build.
6+
7+
## How to update your `engine.js` entrypoint to support Embroider+Vite
8+
9+
To support Embroider+Vite you need to first import `compatModules` from the virtual entrypoint `@embroider/virtual/compat-modules` and then pass it to your resolver using the `withModules()` function. You also need to pass `compatModules` to the `loadInitializers()` function.
10+
11+
```diff
12+
// addon/engine.js
13+
import Engine from 'ember-engines/engine';
14+
import Resolver from 'ember-resolver';
15+
import loadInitializers from 'ember-load-initializers';
16+
import config from './config/environment';
17+
+ import compatModules from '@embroider/virtual/compat-modules';
18+
19+
const { modulePrefix } = config;
20+
21+
class Eng extends Engine {
22+
modulePrefix = config.modulePrefix;
23+
- Resolver = Resolver;
24+
+ Resolver = Resolver.withModules(compatModules);
25+
}
26+
27+
- loadInitializers(Eng, modulePrefix);
28+
+ loadInitializers(Eng, modulePrefix, compatModules);
29+
30+
export default Eng;
31+
```
32+
33+
## Lazy Engines
34+
35+
With the new Embroider+Vite build system you are required to use [`@embroider/router`](https://github.com/embroider-build/embroider/blob/main/packages/router/) as a replacement for your regular Ember Router if you want to maintain the behaviour of your Lazy Engines. All bundle splitting is handled by Embroider and the `@embroider/router` controls loading bundles as you navigate between routes that may have been split by the build, or a lazy engine that may be mounted on a particular route.
36+
37+
The `@embroider/router` is the default for new applications but if you are upgrading an existing app you will need to update your router to use the new drop-in replacement:
38+
39+
```diff
40+
// <your app>/app/router.js
41+
-import EmberRouter from '@ember/routing/router';
42+
+import EmberRouter from '@embroider/router';
43+
```
44+
45+
## Legacy Embroider
46+
47+
Before Embroider+Vite became the default for newly generated applications, there was a previous Embroider version that used a mixture of a classic build (with AMD) and Webpack. This version of Embroider is no longer being actively maintained so anyone still using it should actively try to upgrade to Embroider+Vite.
48+
49+
Since `ember-engines` is providing an automatic polyfill that supports classic builds, that same polyfill allows Engines that have been updated to work with Vite to work with the legacy Emberoider@3 build system that relies on Webpack.

tests/dummy/app/templates/docs/migrations.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Migrations
22

3+
### v0.12 -> v0.13
4+
5+
1. Update engine.js to gain vite support for engines
6+
7+
```diff
8+
// addon/engine.js
9+
import Engine from 'ember-engines/engine';
10+
import Resolver from 'ember-resolver';
11+
import loadInitializers from 'ember-load-initializers';
12+
import config from './config/environment';
13+
+ import compatModules from '@embroider/virtual/compat-modules';
14+
15+
const { modulePrefix } = config;
16+
17+
class Eng extends Engine {
18+
modulePrefix = config.modulePrefix;
19+
- Resolver = Resolver;
20+
+ Resolver = Resolver.withModules(compatModules);
21+
}
22+
23+
- loadInitializers(Eng, modulePrefix);
24+
+ loadInitializers(Eng, modulePrefix, compatModules);
25+
26+
export default Eng;
27+
```
28+
29+
this change is compatible with classic apps that have not upgraded to vite as long as they also upgrade to `ember-engines@^0.13.0`
30+
31+
2. Only on classic apps (not being built with Vite - the default for new apps since 6.8)
32+
Add `ember-asset-loader` as a dev dependency
33+
34+
335
### v0.10 -> v0.11
436

537
1. `@ember/legacy-built-in-components` no longer required for ember engines.

0 commit comments

Comments
 (0)