Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing vite build assets #2163

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/vite/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export function resolver(): Plugin {
const virtualDeps: Map<string, string[]> = new Map();
const notViteDeps = new Set<string>();

let mode = '';

return {
name: 'embroider-resolver',
enforce: 'pre',

configResolved(config) {
mode = config.mode;
},

configureServer(s) {
server = s;
server.watcher.on('all', (_eventName, path) => {
Expand Down Expand Up @@ -94,12 +100,30 @@ export function resolver(): Plugin {
});
this.emitFile({
type: 'asset',
fileName: '@embroider/virtual/test-support.js',
fileName: '@embroider/virtual/vendor.css',
source: virtualContent(
resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),
resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor-styles.css'),
resolverLoader.resolver
).src,
});
if (mode !== 'production') {
this.emitFile({
type: 'asset',
fileName: '@embroider/virtual/test-support.js',
source: virtualContent(
resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),
resolverLoader.resolver
).src,
});
this.emitFile({
type: 'asset',
fileName: '@embroider/virtual/test-support.css',
source: virtualContent(
resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support-styles.css'),
resolverLoader.resolver
).src,
});
}
},
};
}
Expand Down
16 changes: 12 additions & 4 deletions tests/scenarios/compat-addon-classic-features-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { throwOnWarnings } from '@embroider/core';
import { lstatSync, readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import { readFile } from 'fs/promises';
import { merge } from 'lodash';
import QUnit from 'qunit';
Expand Down Expand Up @@ -148,11 +148,19 @@ appScenarios
});

test('virtual scripts are emitted in the build', async function (assert) {
let result = await app.execute('pnpm build');
let result = await app.execute('pnpm build --mode=production');
assert.equal(result.exitCode, 0, result.output);

assert.true(existsSync(`${app.dir}/dist/@embroider/virtual/vendor.js`), 'vendor.js');
assert.false(existsSync(`${app.dir}/dist/@embroider/virtual/test-support.js`), 'test-support.js');

result = await app.execute('pnpm build --mode=development');
assert.equal(result.exitCode, 0, result.output);

assert.true(lstatSync(`${app.dir}/dist/@embroider/virtual/vendor.js`).isFile());
assert.true(lstatSync(`${app.dir}/dist/@embroider/virtual/test-support.js`).isFile());
assert.true(existsSync(`${app.dir}/dist/@embroider/virtual/vendor.js`), 'vendor.js');
assert.true(existsSync(`${app.dir}/dist/@embroider/virtual/test-support.js`), 'test-support.js');
assert.true(existsSync(`${app.dir}/dist/@embroider/virtual/vendor.css`), 'vendor.css');
assert.true(existsSync(`${app.dir}/dist/@embroider/virtual/test-support.css`), 'test-support.css');
});

test('virtual scripts contents are served in dev mode', async function (assert) {
Expand Down
Loading