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 471f4a9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 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
12 changes: 12 additions & 0 deletions packages/vite/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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';



Expand All @@ -13,7 +14,18 @@ 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) => {
const pkg = resolverLoader.resolver.packageCache.ownerOfFile(addon.root);
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

0 comments on commit 471f4a9

Please sign in to comment.