Skip to content

Commit

Permalink
try vite
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Aug 6, 2024
1 parent f50f4fe commit 78c3d0d
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 44 deletions.
11 changes: 10 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import Application from '@ember/application';
import compatModules from '@embroider/core/entrypoint';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'ember-api-docs/config/environment';
import config from './config/environment';

let d = window.define;

for (const [name, module] of Object.entries(compatModules)) {
d(name, function () {
return module;
});
}

import './deprecation-workflow';

Expand Down
3 changes: 3 additions & 0 deletions app/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import loadConfigFromMeta from '@embroider/config-meta-loader';

export default loadConfigFromMeta('ember-api-docs');
21 changes: 12 additions & 9 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AppTemplate</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="{{rootURL}}assets/images/favicon.png">
<meta property="og:type" content="website">

{{content-for "head"}}

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

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/ember-api-docs.js"></script>
<script src="/@embroider/core/vendor.js"></script>
<script type="module">
import Application from './app';
import environment from './config/environment';

Application.create(environment.APP);
</script>

{{content-for "body-footer"}}
</body>
Expand Down
17 changes: 17 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let config;

// TODO - remove this once we have the better solution for injecting stage1 babel config into a real config file
// this is needed because there are things (like ember-composible-helpers) that are now finding our babel config during
// their stage1 build and historically they will never (99% of the time) have found any babel config.
// we might need to keep something like this so that prebuild will never apply babel configs during stage1 i.e. a util
// function that wraps your whole babel config
if (
process.env.EMBROIDER_PREBUILD ||
process.env.EMBROIDER_TEST_SETUP_FORCE === 'classic'
) {
config = {};
} else {
config = require('./node_modules/.embroider/_babel_config_');
}

module.exports = config;
17 changes: 7 additions & 10 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const envIsProduction = process.env.EMBER_ENV === 'production';
const premberUrls = require('./prember-urls');
const nodeSass = require('node-sass');
const { maybeEmbroider } = require('@embroider/test-setup');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {
Expand Down Expand Up @@ -55,14 +55,11 @@ module.exports = function (defaults) {
},
});

const { Webpack } = require('@embroider/webpack');
const appTree = require('@embroider/compat').compatBuild(app, Webpack, {
staticAddonTrees: true,
staticAddonTestSupportTrees: true,
staticHelpers: true,
staticModifiers: true,
staticComponents: true,
return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});

return require('prember').prerender(app, appTree);
};
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.6.0",
"@embroider/compat": "^3.4.3",
"@embroider/core": "^3.4.3",
"@embroider/webpack": "^3.2.1",
"@embroider/compat": "3.5.7-unstable.324f52a",
"@embroider/config-meta-loader": "0.0.1-unstable.324f52a",
"@embroider/core": "3.4.15-unstable.324f52a",
"@embroider/test-setup": "4.0.1-unstable.324f52a",
"@embroider/vite": "0.2.1-unstable.324f52a",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@glint/core": "^0.9.7",
Expand Down Expand Up @@ -79,6 +81,7 @@
"ember-cli-document-title-northm": "^1.0.3",
"ember-cli-fastboot": "^4.1.5",
"ember-cli-htmlbars": "^6.1.1",
"@rollup/plugin-babel": "^6.0.4",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-meta-tags": "^7.0.0",
"ember-cli-sass": "^10.0.1",
Expand All @@ -87,7 +90,6 @@
"ember-composable-helpers": "^3.1.1",
"ember-concurrency": "^2.3.7",
"ember-data": "~3.28.6",
"ember-data-fastboot": "https://github.com/cardstack/ember-data-fastboot#6e6fb8bbf0b405ae174160cc1e4833c5582f68cd",
"ember-export-application-global": "^2.0.1",
"ember-fetch": "^8.1.1",
"ember-inflector": "^4.0.3",
Expand Down Expand Up @@ -143,6 +145,7 @@
"testem": "^3.10.0",
"typescript": "^4.9.3",
"webpack": "^5.90.0"
"vite": "^5.3.4",
},
"engines": {
"node": "16.* || 18.* || 20.*",
Expand Down
35 changes: 15 additions & 20 deletions tests/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>EmberApiDocs Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<title>AppTemplate Tests</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

{{content-for "head"}}
{{content-for "test-head"}}
{{content-for "head"}} {{content-for "test-head"}}

<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/ember-api-docs.css">
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">
<link rel="stylesheet" href="/@embroider/core/vendor.css" />
<link rel="stylesheet" href="/assets/ember-api-docs.css" />
<link rel="stylesheet" href="/@embroider/core/test-support.css" />

{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
{{content-for "head-footer"}} {{content-for "test-head-footer"}}
</head>
<body>
{{content-for "body"}}
{{content-for "test-body"}}
{{content-for "body"}} {{content-for "test-body"}}

<div id="qunit"></div>
<div id="qunit-fixture">
Expand All @@ -29,12 +25,11 @@
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/ember-api-docs.js"></script>
<script src="{{rootURL}}assets/tests.js"></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/@embroider/core/test-entrypoint" type="module"></script>

{{content-for "body-footer"}}
{{content-for "test-body-footer"}}
{{content-for "body-footer"}} {{content-for "test-body-footer"}}
</body>
</html>
73 changes: 73 additions & 0 deletions vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { defineConfig } from 'vite';
import {
resolver,
hbs,
scripts,
templateTag,
optimizeDeps,
compatPrebuild,
assets,
contentFor,
} from '@embroider/vite';
import { resolve } from 'path';
import { babel } from '@rollup/plugin-babel';

const root = 'tmp/rewritten-app';
const extensions = [
'.mjs',
'.gjs',
'.js',
'.mts',
'.gts',
'.ts',
'.hbs',
'.json',
];

export default defineConfig(({ mode }) => {
return {
root,
cacheDir: resolve('node_modules', '.vite'),
resolve: {
extensions,
},
plugins: [
hbs(),
templateTag(),
scripts(),
resolver(),
compatPrebuild(),
assets(),
contentFor(),

babel({
babelHelpers: 'runtime',
extensions,
}),
],
optimizeDeps: optimizeDeps(),
publicDir: resolve(process.cwd(), 'public'),
server: {
port: 4200,
watch: {
ignored: ['!**/tmp/rewritten-app/**'],
},
},
build: {
outDir: resolve(process.cwd(), 'dist'),
rollupOptions: {
input: {
main: resolve(root, 'index.html'),
...(shouldBuildTests(mode)
? { tests: resolve(root, 'tests/index.html') }
: undefined),
},
},
},
};
});

function shouldBuildTests(mode) {
return false;
return mode !== 'production' || process.env.FORCE_BUILD_TESTS;
}

0 comments on commit 78c3d0d

Please sign in to comment.