Skip to content

Commit

Permalink
fix vite build
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Dec 21, 2023
1 parent 1afbab4 commit f67133b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"fs-extra": "^10.0.0",
"jsdom": "^16.6.0",
"source-map-url": "^0.4.1",
"terser": "^5.7.0"
"terser": "^5.7.0",
"fast-glob": "^3.3.2"
},
"devDependencies": {
"@embroider/core": "workspace:^",
Expand Down
18 changes: 14 additions & 4 deletions packages/vite/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Plugin } from 'vite';
import * as process from 'process';
import { dirname, join } from 'path';
import { copyFileSync, mkdirpSync } from 'fs-extra';


import glob from 'fast-glob';

export function assets(): Plugin {
const cwd = process.cwd();
Expand All @@ -13,14 +12,25 @@ export function assets(): Plugin {
return {
name: 'assets',
enforce: 'pre',
outputOptions(options) {
options.dir = join(process.cwd(), 'dist');
},
async writeBundle(options) {
const pubDir = join(process.cwd(), 'public');
const publicAppFiles = glob.sync('**/*', {
cwd: pubDir,
});
for (const publicAppFile of publicAppFiles) {
mkdirpSync(dirname(join(options.dir!, publicAppFile)));
copyFileSync(join(pubDir, publicAppFile), join(options.dir!, publicAppFile));
}
for (const engine of engines) {
engine.activeAddons.forEach((addon) => {
engine.activeAddons.forEach(addon => {
const pkg = resolverLoader.resolver.packageCache.ownerOfFile(addon.root);
if (!pkg || !pkg.isV2Addon()) return;
const assets = pkg.meta['public-assets'] || {};
Object.entries(assets).forEach(([path, dest]) => {
mkdirpSync(dirname(join(options.dir!, dest)))
mkdirpSync(dirname(join(options.dir!, dest)));
copyFileSync(join(pkg.root, path), join(options.dir!, dest));
});
});
Expand Down
8 changes: 7 additions & 1 deletion packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import { hbsToJS } from '@embroider/core';
import assertNever from 'assert-never';
import { parse as pathParse } from 'path';
import makeDebug from 'debug';
import { RollupModuleRequest } from './request';

const debug = makeDebug('embroider:hbs-plugin');

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) {
let request = RollupModuleRequest.from(source, importer, options.custom);
if (!request) {
// fallthrough to other rollup plugins
return null;
}
let resolution = await this.resolve(source, importer, {
skipSelf: true,
});
Expand Down
8 changes: 7 additions & 1 deletion packages/vite/src/template-tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createFilter } from '@rollup/pluginutils';
import type { Plugin } from 'vite';
import { Preprocessor } from 'content-tag';
import { RollupModuleRequest } from './request';

const gjsFilter = createFilter('**/*.gjs?(\\?)*');

Expand All @@ -15,7 +16,12 @@ export function templateTag(): Plugin {
name: 'embroider-template-tag',
enforce: 'pre',

async resolveId(id: string, importer: string | undefined) {
async resolveId(id: string, importer: string | undefined, options) {
let request = RollupModuleRequest.from(id, importer, options.custom);
if (!request) {
// fallthrough to other rollup plugins
return null;
}
let resolution = await this.resolve(id, importer, {
skipSelf: true,
});
Expand Down
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion tests/vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test": "tests"
},
"scripts": {
"build": "ember build --environment=production",
"ember:build": "ember build",
"build": "vite build",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:css": "stylelint \"**/*.css\"",
"lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",
Expand Down
2 changes: 1 addition & 1 deletion tests/vite-app/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
templateTag,
optimizeDeps,
assets,
} from '@embroider/vite';
} from "@embroider/vite";
import { resolve } from "path";
import { babel } from "@rollup/plugin-babel";

Expand Down

0 comments on commit f67133b

Please sign in to comment.