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: rollup-hbs-plugin add resolveId hook #1171

Merged
merged 2 commits into from
Mar 31, 2022
Merged
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
32 changes: 29 additions & 3 deletions packages/addon-dev/src/rollup-hbs-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,41 @@ export default function rollupHbsPlugin(): Plugin {

return {
name: 'rollup-hbs-plugin',
async resolveId(source: string, importer: string | undefined, options) {
const resolution = await this.resolve(source, importer, {
skipSelf: true,
...options,
});

const id = resolution?.id;

if (!filter(id)) return null;

// This creates an `*.hbs.js` that we will populate in `load()` hook.
return {
...resolution,
id: id + '.js',
meta: {
'rollup-hbs-plugin': {
originalId: id,
},
},
};
},
load(id: string) {
if (!filter(id)) return;
let input = readFileSync(id, 'utf8');
const meta = this.getModuleInfo(id)?.meta;
const originalId = meta?.['rollup-hbs-plugin']?.originalId;

if (!originalId) {
return;
}

let input = readFileSync(originalId, 'utf8');
let code =
`import { hbs } from 'ember-cli-htmlbars';\n` +
`export default hbs${backtick}${input}${backtick};`;
return {
code,
id: id + '.js',
};
},
};
Expand Down