Skip to content

Commit c545d16

Browse files
committed
try vite
1 parent ff0844c commit c545d16

File tree

8 files changed

+137
-44
lines changed

8 files changed

+137
-44
lines changed

app/app.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import Application from '@ember/application';
2+
import compatModules from '@embroider/core/entrypoint';
23
import Resolver from 'ember-resolver';
34
import loadInitializers from 'ember-load-initializers';
4-
import config from 'ember-api-docs/config/environment';
5+
import config from './config/environment';
6+
7+
let d = window.define;
8+
9+
for (const [name, module] of Object.entries(compatModules)) {
10+
d(name, function () {
11+
return module;
12+
});
13+
}
514

615
export default class App extends Application {
716
modulePrefix = config.modulePrefix;

app/config/environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import loadConfigFromMeta from '@embroider/config-meta-loader';
2+
3+
export default loadConfigFromMeta('ember-api-docs');

app/index.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
5+
<title>AppTemplate</title>
6+
<meta name="description" content="">
67
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<link rel="shortcut icon" href="{{rootURL}}assets/images/favicon.png">
8-
<meta property="og:type" content="website">
98

109
{{content-for "head"}}
1110

12-
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
13-
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/ember-api-docs.css">
14-
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600" rel="stylesheet">
11+
<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
12+
<link integrity="" rel="stylesheet" href="/assets/ember-api-docs.css">
1513

1614
{{content-for "head-footer"}}
1715
</head>
1816
<body>
1917
{{content-for "body"}}
2018

21-
<script src="{{rootURL}}assets/vendor.js"></script>
22-
<script src="{{rootURL}}assets/ember-api-docs.js"></script>
19+
<script src="/@embroider/core/vendor.js"></script>
20+
<script type="module">
21+
import Application from './app';
22+
import environment from './config/environment';
23+
24+
Application.create(environment.APP);
25+
</script>
2326

2427
{{content-for "body-footer"}}
2528
</body>

babel.config.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let config;
2+
3+
// TODO - remove this once we have the better solution for injecting stage1 babel config into a real config file
4+
// this is needed because there are things (like ember-composible-helpers) that are now finding our babel config during
5+
// their stage1 build and historically they will never (99% of the time) have found any babel config.
6+
// we might need to keep something like this so that prebuild will never apply babel configs during stage1 i.e. a util
7+
// function that wraps your whole babel config
8+
if (
9+
process.env.EMBROIDER_PREBUILD ||
10+
process.env.EMBROIDER_TEST_SETUP_FORCE === 'classic'
11+
) {
12+
config = {};
13+
} else {
14+
config = require('./node_modules/.embroider/_babel_config_');
15+
}
16+
17+
module.exports = config;

ember-cli-build.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');
44
const Funnel = require('broccoli-funnel');
55
const mergeTrees = require('broccoli-merge-trees');
66
const envIsProduction = process.env.EMBER_ENV === 'production';
7-
const premberUrls = require('./prember-urls');
87
const nodeSass = require('node-sass');
8+
const { maybeEmbroider } = require('@embroider/test-setup');
99

1010
module.exports = function (defaults) {
1111
let app = new EmberApp(defaults, {
@@ -63,14 +63,11 @@ module.exports = function (defaults) {
6363
destDir: '/assets/',
6464
});
6565

66-
const { Webpack } = require('@embroider/webpack');
67-
const appTree = require('@embroider/compat').compatBuild(app, Webpack, {
68-
staticAddonTrees: true,
69-
staticAddonTestSupportTrees: true,
70-
staticHelpers: true,
71-
staticModifiers: true,
72-
staticComponents: true,
66+
return maybeEmbroider(app, {
67+
skipBabel: [
68+
{
69+
package: 'qunit',
70+
},
71+
],
7372
});
74-
75-
return mergeTrees([require('prember').prerender(app, appTree), mappingsTree]);
7673
};

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
"devDependencies": {
3030
"@ember/optional-features": "^2.0.0",
3131
"@ember/test-helpers": "^2.6.0",
32-
"@embroider/compat": "^3.4.3",
33-
"@embroider/core": "^3.4.3",
34-
"@embroider/webpack": "^3.2.1",
32+
"@embroider/compat": "3.5.7-unstable.324f52a",
33+
"@embroider/config-meta-loader": "0.0.1-unstable.324f52a",
34+
"@embroider/core": "3.4.15-unstable.324f52a",
35+
"@embroider/test-setup": "4.0.1-unstable.324f52a",
36+
"@embroider/vite": "0.2.1-unstable.324f52a",
3537
"@glimmer/component": "^1.1.2",
3638
"@glimmer/tracking": "^1.1.2",
3739
"@glint/core": "^0.9.7",
@@ -80,6 +82,7 @@
8082
"ember-cli-document-title-northm": "^1.0.3",
8183
"ember-cli-fastboot": "^4.1.5",
8284
"ember-cli-htmlbars": "^6.1.1",
85+
"@rollup/plugin-babel": "^6.0.4",
8386
"ember-cli-inject-live-reload": "^2.1.0",
8487
"ember-cli-meta-tags": "^7.0.0",
8588
"ember-cli-sass": "^10.0.1",
@@ -88,7 +91,6 @@
8891
"ember-composable-helpers": "^3.1.1",
8992
"ember-concurrency": "^2.3.7",
9093
"ember-data": "~3.28.6",
91-
"ember-data-fastboot": "https://github.com/cardstack/ember-data-fastboot#6e6fb8bbf0b405ae174160cc1e4833c5582f68cd",
9294
"ember-export-application-global": "^2.0.1",
9395
"ember-fetch": "^8.1.1",
9496
"ember-inflector": "^3.0.0",
@@ -144,6 +146,7 @@
144146
"testem": "^3.10.0",
145147
"typescript": "^4.9.3",
146148
"webpack": "^5.90.0"
149+
"vite": "^5.3.4",
147150
},
148151
"engines": {
149152
"node": "16.* || 18.* || 20.*",

tests/index.html

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<title>EmberApiDocs Tests</title>
7-
<meta name="description" content="">
8-
<meta name="viewport" content="width=device-width, initial-scale=1">
4+
<meta charset="utf-8" />
5+
<title>AppTemplate Tests</title>
6+
<meta name="description" content="" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
98

10-
{{content-for "head"}}
11-
{{content-for "test-head"}}
9+
{{content-for "head"}} {{content-for "test-head"}}
1210

13-
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
14-
<link rel="stylesheet" href="{{rootURL}}assets/ember-api-docs.css">
15-
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">
11+
<link rel="stylesheet" href="/@embroider/core/vendor.css" />
12+
<link rel="stylesheet" href="/assets/ember-api-docs.css" />
13+
<link rel="stylesheet" href="/@embroider/core/test-support.css" />
1614

17-
{{content-for "head-footer"}}
18-
{{content-for "test-head-footer"}}
15+
{{content-for "head-footer"}} {{content-for "test-head-footer"}}
1916
</head>
2017
<body>
21-
{{content-for "body"}}
22-
{{content-for "test-body"}}
18+
{{content-for "body"}} {{content-for "test-body"}}
2319

2420
<div id="qunit"></div>
2521
<div id="qunit-fixture">
@@ -29,12 +25,11 @@
2925
</div>
3026

3127
<script src="/testem.js" integrity="" data-embroider-ignore></script>
32-
<script src="{{rootURL}}assets/vendor.js"></script>
33-
<script src="{{rootURL}}assets/test-support.js"></script>
34-
<script src="{{rootURL}}assets/ember-api-docs.js"></script>
35-
<script src="{{rootURL}}assets/tests.js"></script>
28+
<script src="/@embroider/core/vendor.js"></script>
29+
<script src="/@embroider/core/test-support.js"></script>
30+
<script src="/@embroider/core/entrypoint" type="module"></script>
31+
<script src="/@embroider/core/test-entrypoint" type="module"></script>
3632

37-
{{content-for "body-footer"}}
38-
{{content-for "test-body-footer"}}
33+
{{content-for "body-footer"}} {{content-for "test-body-footer"}}
3934
</body>
4035
</html>

vite.config.mjs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { defineConfig } from 'vite';
2+
import {
3+
resolver,
4+
hbs,
5+
scripts,
6+
templateTag,
7+
optimizeDeps,
8+
compatPrebuild,
9+
assets,
10+
contentFor,
11+
} from '@embroider/vite';
12+
import { resolve } from 'path';
13+
import { babel } from '@rollup/plugin-babel';
14+
15+
const root = 'tmp/rewritten-app';
16+
17+
export default defineConfig(({ mode }) => {
18+
return {
19+
root,
20+
// esbuild in vite does not support decorators
21+
esbuild: false,
22+
cacheDir: resolve('node_modules', '.vite'),
23+
plugins: [
24+
hbs(),
25+
templateTag(),
26+
scripts(),
27+
resolver(),
28+
compatPrebuild(),
29+
assets(),
30+
contentFor(),
31+
32+
babel({
33+
babelHelpers: 'runtime',
34+
35+
// this needs .hbs because our hbs() plugin above converts them to
36+
// javascript but the javascript still also needs babel, but we don't want
37+
// to rename them because vite isn't great about knowing how to hot-reload
38+
// them if we resolve them to made-up names.
39+
extensions: ['.gjs', '.js', '.hbs', '.ts', '.gts'],
40+
}),
41+
],
42+
optimizeDeps: optimizeDeps(),
43+
publicDir: resolve(process.cwd(), 'public'),
44+
server: {
45+
port: 4200,
46+
watch: {
47+
ignored: ['!**/tmp/rewritten-app/**'],
48+
},
49+
},
50+
build: {
51+
outDir: resolve(process.cwd(), 'dist'),
52+
rollupOptions: {
53+
input: {
54+
main: resolve(root, 'index.html'),
55+
...(shouldBuildTests(mode)
56+
? { tests: resolve(root, 'tests/index.html') }
57+
: undefined),
58+
},
59+
},
60+
},
61+
};
62+
});
63+
64+
function shouldBuildTests(mode) {
65+
return mode !== 'production' || process.env.FORCE_BUILD_TESTS;
66+
}

0 commit comments

Comments
 (0)