Skip to content

Commit

Permalink
fix vite build
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Feb 9, 2024
1 parent 43da932 commit a1949cb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ export function hbs(): Plugin {
return {
name: 'rollup-hbs-plugin',
enforce: 'pre',
async resolveId(source: string, importer: string | undefined) {
async resolveId(source: string, importer: string | undefined, options) {
if (options.custom?.onlyResolver) {
return null;
}
let resolution = await this.resolve(source, importer, {
skipSelf: true,
custom: {
onlyResolver: true,
},
});

if (!resolution) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function resolver(): Plugin {
if (id.startsWith(virtualPrefix)) {
let { src, watches } = virtualContent(id.slice(virtualPrefix.length), resolverLoader.resolver);
virtualDeps.set(id, watches);
server.watcher.add(watches);
server?.watcher.add(watches);
return src;
}
},
Expand Down
9 changes: 8 additions & 1 deletion packages/vite/src/template-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export function templateTag({ inline_source_map } = { inline_source_map: false }
name: 'embroider-template-tag',
enforce: 'pre',

async resolveId(id: string, importer: string | undefined) {
async resolveId(id: string, importer: string | undefined, options) {
if (options.custom?.onlyResolver) {
return null;
}
let resolution = await this.resolve(id, importer, {
skipSelf: true,
custom: {
onlyResolver: true,
},
});
if (resolution) {
return resolution;
Expand All @@ -26,6 +32,7 @@ export function templateTag({ inline_source_map } = { inline_source_map: false }
resolution = await this.resolve(candidate, importer, {
skipSelf: true,
custom: {
onlyResolver: true,
embroider: {
enableCustomResolver: false,
},
Expand Down
28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/scenarios/vite-app-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,16 @@ viteAppScenarios
const depCache = readdirSync(join(app.dir, 'node_modules', '.vite', 'deps'));
assert.ok(depCache.length > 0, 'should have created cached deps');
});

test(`pnpm build`, async function (assert) {
let result = await app.execute('pnpm build');
assert.equal(result.exitCode, 0, result.output);
const distFiles = readdirSync(join(app.dir, 'dist'));
assert.ok(distFiles.length > 1, 'should have created dist folder');
assert.ok(distFiles.includes('assets'), 'should have created assets folder');

const assetFiles = readdirSync(join(app.dir, 'dist', 'assets'));
assert.ok(assetFiles.length > 1, 'should have created asset files');
});
});
});
1 change: 1 addition & 0 deletions tests/vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"broccoli-asset-rev": "^3.0.0",
"concurrently": "^8.2.0",
"ember-auto-import": "^2.6.3",
Expand Down
7 changes: 7 additions & 0 deletions tests/vite-app/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
compatPrebuild,
} from "@embroider/vite";
import { resolve } from "path";
import rollupResolve from "@rollup/plugin-node-resolve";
import { babel } from "@rollup/plugin-babel";

const root = "node_modules/.embroider/rewritten-app";
Expand Down Expand Up @@ -42,7 +43,13 @@ export default defineConfig({
},
},
build: {
outDir: resolve(process.cwd(), "dist"),
rollupOptions: {
plugins: [
rollupResolve({
extensions: [".gjs", ".js", ".hbs", ".ts", ".gts"],
}),
],
input: {
main: resolve(root, "index.html"),
tests: resolve(root, "tests/index.html"),
Expand Down

0 comments on commit a1949cb

Please sign in to comment.