Skip to content

Commit cfb679e

Browse files
authored
Merge pull request #2162 from ember-learn/vite
Vite Tracking Branch
2 parents db088d8 + 9cdb491 commit cfb679e

File tree

81 files changed

+276
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+276
-362
lines changed

.local.dic

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BelongsTo
2222
blockquote
2323
blogPost
2424
bookmarklet
25-
Browserlist
25+
Browserslist
2626
callouts
2727
camelize
2828
centric
@@ -52,6 +52,7 @@ debounce
5252
declaratively
5353
DefinitelyTyped
5454
deps
55+
dev
5556
draggable
5657
dropdown
5758
durations
@@ -62,6 +63,7 @@ els-addon-typed-templates
6263
ember-a11y
6364
ember-a11y-refocus
6465
ember-a11y-testing
66+
ember-cli
6567
ember-cli-cjs-transform
6668
ember-cli-deprecation-workflow
6769
ember-cli-document-title
@@ -130,6 +132,7 @@ linters
130132
lookups
131133
LSP
132134
Mapbox
135+
TomTom
133136
MDN
134137
metaprogramming
135138
misspelt
@@ -178,6 +181,8 @@ rerender
178181
rerendering
179182
rerenders
180183
RequestManager
184+
rollup
185+
Rollup
181186
routable
182187
RunDOC
183188
runnable
@@ -217,6 +222,7 @@ templating
217222
TextMate
218223
todo
219224
todos
225+
toolchain
220226
tooltip
221227
tooltips
222228
trackable
@@ -253,3 +259,6 @@ working-with-html-css-and-javascript
253259
yay
254260
ZEIT
255261
userQuestion
262+
vite
263+
Vite
264+
bundler

.remarkignore

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,9 @@ MAINTAINERS.md
55
# old major versions
66
guides/v1*/**/*.md
77
guides/v2*/**/*.md
8-
9-
# current major version
10-
guides/v3.0.0/**/*.md
11-
guides/v3.1.0/**/*.md
12-
guides/v3.2.0/**/*.md
13-
guides/v3.3.0/**/*.md
14-
guides/v3.4.0/**/*.md
15-
guides/v3.5.0/**/*.md
16-
guides/v3.6.0/**/*.md
17-
guides/v3.7.0/**/*.md
18-
guides/v3.8.0/**/*.md
19-
guides/v3.9.0/**/*.md
20-
guides/v3.10.0/**/*.md
21-
guides/v3.11.0/**/*.md
22-
guides/v3.12.0/**/*.md
23-
guides/v3.13.0/**/*.md
24-
guides/v3.14.0/**/*.md
25-
guides/v3.15.0/**/*.md
26-
guides/v3.16.0/**/*.md
27-
guides/v3.17.0/**/*.md
28-
guides/v3.18.0/**/*.md
29-
guides/v3.19.0/**/*.md
30-
guides/v3.20.0/**/*.md
31-
guides/v3.21.0/**/*.md
32-
guides/v3.22.0/**/*.md
33-
guides/v3.23.0/**/*.md
34-
guides/v3.24.0/**/*.md
35-
guides/v3.25.0/**/*.md
36-
guides/v3.26.0/**/*.md
37-
guides/v3.27.0/**/*.md
8+
guides/v3*/**/*.md
9+
guides/v4*/**/*.md
10+
guides/v5*/**/*.md
3811

3912
# redirect only files
4013
guides/release/working-with-javascript

guides/release/addons-and-dependencies/index.md

Lines changed: 7 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -2,171 +2,30 @@ As you're developing your Ember app, you are likely to run into common scenarios
22
Perhaps you want to use a CSS preprocessor to write your stylesheets, or you want to use a popular JS library, or maybe
33
you want to import components written by a different department within your organization.
44

5-
Ember CLI provides a common format called [Ember Addons](#toc_addons) for distributing reusable libraries to solve some
5+
Ember provides a common format called [Ember Addons](#toc_addons) for distributing reusable libraries to solve some
66
of these problems. Additionally, you may want to make use of front-end dependencies like a CSS framework or a JavaScript
77
datepicker that aren't specific to Ember apps.
88

99
## Addons
1010

11-
Addons are JavaScript packages that integrate with Ember. For example, [`ember-cli-sass`](https://github.com/adopted-ember-addons/ember-cli-sass)
12-
is an addon that allows you to use SASS/SCSS in your applications. You can install it using the Ember CLI with the following command:
11+
Addons are JavaScript packages that integrate with Ember. For example, [`ember-concurrency`](https://github.com/machty/ember-concurrency) provides a concurrency primitive that you can use in your Ember app as well as a [Babel](https://babeljs.io/) plugin that makes it easier to use in an Ember application. You can install it just like any other npm package:
1312

1413
```bash
15-
ember install ember-cli-sass
14+
npm install --save-dev ember-cli-sass
1615
```
1716

18-
This will modify your `package.json` (and `package-lock.json` or `yarn.lock` or `pnpm-lock.yaml`), typically bringing in other dependencies. Some addons will also add
19-
additional files to your projects when relevant.
20-
21-
There are many addons that cover all kinds of use cases. For more detail, as well as examples of what addons can do,
22-
we invite you to have a look at the [Ember CLI documentation](https://cli.emberjs.com/release/basic-use/using-addons/).
17+
And then follow any additional instructions in the README of the addon. Some addons (like `ember-concurrency`) will give instructions for extra steps that you might need like installing a Babel plugin so it's always worthwhile reading the installation documentation.
2318

2419
The Ember community publishes and maintains many addons, and it can be difficult to know if one (or many!) exists that covers
2520
your needs. The website [Ember Observer](https://www.emberobserver.com/) keeps an up-to-date index of Ember Addons, sorted by
2621
categories, and rated according to objective metrics. If you are looking for an addon, we recommend that you start there!
2722

2823
## Regular npm packages
2924

30-
While dependencies can be managed in several ways,
31-
it's worth noting that the process can be greatly simplified for new developers by using ember-auto-import,
32-
which offers zero config imports from npm packages.
33-
It's built into new Ember apps by default and can be installed in older apps by using `ember install ember-auto-import`.
34-
For further usage instructions, please follow the [project README](https://github.com/ef4/ember-auto-import).
35-
36-
## Other assets
37-
38-
Third-party JavaScript not available as an addon or npm package should be placed in the `vendor/` folder in your project.
39-
40-
Your own assets (such as `robots.txt`, `favicon`, custom fonts, etc) should be placed in the `public/` folder in your project.
41-
42-
## Compiling Assets
43-
44-
When you're using dependencies that are not included in an addon,
45-
you will have to instruct Ember CLI to include your assets in the build.
46-
This is done using the asset manifest file `ember-cli-build.js`.
47-
You should only try to import assets located in the `node_modules` and `vendor` folders.
48-
49-
### Globals provided by JavaScript assets
50-
51-
The globals provided by some assets (like `moment` in the below example) can be used in your application
52-
without the need to `import` them.
53-
Provide the asset path as the first and only argument.
54-
55-
```javascript {data-filename=ember-cli-build.js}
56-
app.import('node_modules/moment/moment.js');
57-
```
58-
59-
You will need to add `"moment"` to the `globals` section in `.eslintrc.js` to prevent ESLint errors
60-
about using an undefined variable.
61-
62-
### Anonymous AMD JavaScript modules
63-
64-
You can transform an anonymous AMD module to a named one by using the `amd` transformation.
65-
66-
```javascript {data-filename=ember-cli-build.js}
67-
app.import('node_modules/moment/moment.js', {
68-
using: [
69-
{ transformation: 'amd', as: 'moment' }
70-
]
71-
});
72-
```
73-
74-
This transformation allows you to `import` moment in your app. (e.g. `import moment from 'moment';`)
75-
76-
### CommonJS JavaScript modules
77-
78-
[ember-cli-cjs-transform](https://github.com/rwjblue/ember-cli-cjs-transform) allows us to import CommonJS modules into
79-
our Ember app. It also does auto-rollup and some nice caching, so it should pull in all the deps that are pulled in
80-
with `require` for you automatically. It is not yet included with Ember CLI by default, so you will need to install it.
81-
82-
```bash
83-
ember install ember-cli-cjs-transform
84-
```
85-
86-
```javascript {data-filename=ember-cli-build.js}
87-
app.import('node_modules/showdown/dist/showdown.js', {
88-
using: [
89-
{ transformation: 'cjs', as: 'showdown' }
90-
]
91-
});
92-
```
93-
94-
You can now `import` them in your app. (e.g. `import showdown from 'showdown';`)
95-
96-
### Environment-Specific Assets
25+
For newly generated Ember apps, the majority of the build is managed by [Vite](https://vite.dev/) which means that any npm packages or other assets can just be imported as you might expect in a modern build system or bundler.
9726

98-
If you need to use different assets in different environments, specify an object as the first parameter.
99-
That object's key should be the environment name, and the value should be the asset to use in that environment.
27+
In previous versions of Ember (before we moved to using Vite) there were other concepts that you would need to know to include 3rd party packages or assets in your app. If you are working on an Ember app that hasn't yet been upgraded to Vite you should look at [previous versions of this guide](/v6.7.0/addons-and-dependencies/) to get more information about the legacy build system.
10028

101-
```javascript {data-filename=ember-cli-build.js}
102-
app.import({
103-
development: 'node_modules/moment/moment.js',
104-
production: 'node_modules/moment/min/moment.min.js'
105-
});
106-
```
107-
108-
If you need to import an asset in only one environment you can wrap `app.import` in an `if` statement.
109-
For assets needed during testing, you should also use the `{type: 'test'}` option to make sure they
110-
are available in test mode.
111-
112-
```javascript {data-filename=ember-cli-build.js}
113-
if (app.env === 'development') {
114-
// Only import when in development mode
115-
app.import('vendor/ember-renderspeed/ember-renderspeed.js');
116-
}
117-
if (app.env === 'test') {
118-
// Only import in test mode and place in test-support.js
119-
app.import('node_modules/sinonjs/sinon.js', { type: 'test' });
120-
app.import('node_modules/sinon-qunit/lib/sinon-qunit.js', { type: 'test' });
121-
}
122-
```
123-
124-
### CSS
125-
126-
Provide the asset path as the first argument:
127-
128-
```javascript {data-filename=ember-cli-build.js}
129-
app.import('node_modules/foundation/css/foundation.css');
130-
```
131-
132-
All style assets added this way will be concatenated and output as `/assets/vendor.css`.
133-
134-
### Other Assets
135-
136-
All assets located in the `public/` folder will be copied as is to the final output directory, `dist/`.
137-
138-
For example, a `favicon` located at `public/images/favicon.ico` will be copied to `dist/images/favicon.ico`.
139-
140-
All third-party assets, included either manually in `vendor/` or via a package manager like npm, must be added via `app.import()`.
141-
142-
Third-party assets that are not added via `app.import()` will not be present in the final build.
143-
144-
By default, `import`ed assets will be copied to `dist/` as they are, with the existing directory structure maintained.
145-
146-
```javascript {data-filename=ember-cli-build.js}
147-
app.import('node_modules/font-awesome/fonts/fontawesome-webfont.ttf');
148-
```
149-
150-
This example would create the font file in `dist/font-awesome/fonts/fontawesome-webfont.ttf`.
151-
152-
You can also optionally tell `import()` to place the file at a different path.
153-
The following example will copy the file to `dist/assets/fontawesome-webfont.ttf`.
154-
155-
```javascript {data-filename=ember-cli-build.js}
156-
app.import('node_modules/font-awesome/fonts/fontawesome-webfont.ttf', {
157-
destDir: 'assets'
158-
});
159-
```
160-
161-
If you need to load certain dependencies before others,
162-
you can set the `prepend` property equal to `true` on the second argument of `import()`.
163-
This will prepend the dependency to the vendor file instead of appending it, which is the default behavior.
164-
165-
```javascript {data-filename=ember-cli-build.js}
166-
app.import('node_modules/es5-shim/es5-shim.js', {
167-
type: 'vendor',
168-
prepend: true
169-
});
170-
```
29+
To know more about how Vite can be configured, e.g. how it [handles static assets](https://vite.dev/guide/assets), you can consult their guides: [https://vite.dev/guide/](https://vite.dev/guide/)
17130

17231
<!-- eof - needed for pages that end in a code block -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Ember supports two different build environments:
2+
3+
- Our [Vite integration](./vite) works on all Ember versions back to 3.28. It became the default for newly-generated apps at Ember 6.8.
4+
- The legacy [ember-cli based build](https://cli.emberjs.com/release/) is also still supported on all Ember versions.
5+
6+
You can tell which one you're using based on the presence of `@embroider/vite` in your `package.json` file.
7+
8+
Existing apps can use [Ember Vite Codemod](https://github.com/mainmatter/ember-vite-codemod) to switch from the ember-cli based build to the Vite based build.
9+
10+
On Ember versions after 6.8, you can optionally choose to generate a new app using the older build environment via:
11+
12+
```sh
13+
npx ember-cli@ new my-app-name -b @ember-tooling/classic-build-app-blueprint
14+
```
15+
16+
17+

guides/release/build-tools/vite.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
When you generate a new Ember app your default build system will be using Vite.
2+
3+
> Vite is a blazing fast frontend build tool powering the next generation of web applications.
4+
5+
You can read more about [Vite on their documentation](https://vite.dev/guide/) site. Ember's Vite implementation is [powered by Embroider](https://github.com/embroider-build/embroider), which acts as a Vite plugin that allows Vite to effectively build an Ember app.
6+
7+
## Basic Usage
8+
9+
For most developers the only interaction that they will have with the build system is running the `npm start`, or `npm run build` scripts defined in their `package.json`. If you have a look at your `package.json` scripts you will see that they are just deferring to `vite` (which by default runs `vite dev` and starts the Vite dev server) and `vite build` respectively.
10+
11+
You can see more docs on these commands in the Vite documentation
12+
13+
### Sensible defaults
14+
15+
As Ember developers we expect reasonable defaults, because of that we have provided a default vite config for you that takes care of most of the Vite configuration you need as an Ember developer. For example, we automatically include your `tests/index.html` in the `build.rollupOptions.input` when you are building in `develoment` mode so that you can navigate to http://localhost:4200/tests/
16+
17+
For most applications you will not need to override the config that we provide by default, instead you can just add to the config as you need. If you do need to change the defaults that we provide, you can just define the new configuration in your `vite.config.js` because anything you define there will take precedence over anything we provide.
18+
19+
20+
### Integrating 3rd party plugins
21+
22+
Now that Ember uses Vite for its build system, you no longer need an Ember-specific plugin to augment your build. If you find a Vite or rollup plugin that you would like to use you can follow the installation instructions to add that to your `vite.config.js` without any Ember-specific instructions necessary.
23+
24+
## Advanced Usage
25+
26+
Most developers will not need to change the defaults that we provide, but in some rare cases it can be useful to know how to change the defaults.
27+
28+
### Running Tests Against Production Code
29+
30+
By default, we don't build your tests when you build for production. This is because, in most cases, people don't want their tests included in the bundle they ship to end-users. This means if you run `npm run build` in your app it will default to `--mode production` (because this is [the default for `vite build`](https://vite.dev/config/shared-options.html#mode)) and it will not include your tests in your build output.
31+
32+
If you needed to run your tests against your production environment for any reason (maybe you have a vite/rollup plugin that you only run during your production build) then you can use the `FORCE_BUILD_TESTS=true` environment variable. This is just a convenience in the code that the default `ember()` plugin provides, you can always define your inputs in the `vite.config.js` which will take precedent over anything we're doing automatically for you in the `ember()` plugin.
Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
Ember application builds are created by the Ember CLI build pipeline. Just as with your application code,
2-
Ember CLI ships with a sensible set of defaults to compile and bundle the assets that can be deployed
3-
to production. Under the hood, this is accomplished using a series of Broccoli plugins, each of which
4-
can be configured in the `ember-cli-build.js` file at the root of your project.
5-
6-
Ember CLI uses [Babel.js](https://babeljs.io/) for the compile step in this process. If you've used Babel
7-
before, you know that it comes with a large set of options, including the ability to configure
8-
"targets"; i.e. the environments in which your application is expected to run.
9-
For example, if your application is embedded in an [Electron app](https://www.electronjs.org),
10-
you might only care about compiling for the latest Chromium build. Or if your app targets Enterprise
11-
users, you may need to compile your JavaScript to older syntax that runs in IE11.
12-
13-
For any of these cases, you can configure `ember build` to do The Right Thing. You can read more about
14-
this in [the Ember CLI Guides](https://cli.emberjs.com/release/advanced-use/build-targets/)!
1+
By default, Ember apps are built with Vite. The toolchain uses Babel, esbuild, and Rollup so you can write current-generation JavaScript and TypeScript while still allowing your application to work with older browsers.
2+
3+
Rather than always compiling everything down to legacy syntax, Ember determines what—if anything—needs to be transformed based on the browsers you target. With today’s defaults aimed at evergreen browsers, many features (ES modules, classes, arrow functions, async/await, etc.) ship largely as-is.
4+
5+
Why does this matter? Over-transpiling to very old JavaScript increases bundle size, slows parsing, and in some cases can slow down the execution of your JavaScript code. As the Web platform has advanced and percentage of users on legacy browsers have decreased, Ember’s default targets avoid unnecessary transforms to keep apps smaller and faster.
6+
7+
If you need to update the defaults for any reason (i.e. need to target a very legacy browser), you can set the targets for your app and the compiler applies only the minimal transforms and polyfills required for those browsers.
8+
9+
If you open `config/targets.js`, you will find the following code:
10+
11+
```javascript {data-filename=config/targets.js}
12+
"use strict";
13+
14+
const browsers = [
15+
"last 1 Chrome versions",
16+
"last 1 Firefox versions",
17+
"last 1 Safari versions",
18+
];
19+
20+
module.exports = {
21+
browsers,
22+
};
23+
```
24+
25+
If you inspect your compiled code after running a build with `npm run build`, you'll see that many modern features (like arrow functions and async/await) preserved when your targets support them.
26+
27+
This feature is backed by [Browserslist](https://github.com/ai/browserslist) and [Can I Use](https://caniuse.com/).
28+
These websites track usage stats of browsers, so you can use complex queries based on the user base of every browser.
29+
30+
If you want to target all browsers with more than a 4% market share in Canada,
31+
you'd have the following options:
32+
33+
```javascript {data-filename=config/targets.js}
34+
module.exports = {
35+
browsers: ["> 4% in CA"],
36+
};
37+
```
38+
39+
It is very important that you properly configure the targets of your app so you get the smallest and fastest code possible.

guides/release/configuring-ember/optional-features.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ To give the project a path forward when a breaking change is mandatory, we've re
77

88
This addon does nothing by default, but provides a command-line interface to enable and disable breaking changes in Ember.
99

10-
## Installation
11-
12-
To get started with optional features, you must install the addon:
13-
14-
```bash
15-
ember install @ember/optional-features
16-
```
17-
18-
This will make three new commands available to Ember CLI within your project, `feature:list`, `feature:enable`, and `feature:disable`.
10+
`@ember/optional-features` is installed by default when generating a new ember application.
1911

2012
## Listing features
2113

0 commit comments

Comments
 (0)