Skip to content

Commit 4ca0f52

Browse files
committed
feat: add support for raw imports
1 parent 040b177 commit 4ca0f52

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/instrument-bundler/src/plugin.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
2929
path: args.path
3030
};
3131
});
32+
build.onLoad({ filter: /.+\?raw$/, namespace: namespaces.bundle }, (args) => {
33+
const input = resolveInput(/(.+)\?raw$/.exec(args.path)![1]!, options.inputs);
34+
if (!input) {
35+
return {
36+
errors: [
37+
{
38+
location: { file: args.path },
39+
text: `Failed to resolve '${args.path}' from input filenames: ${options.inputs.map((file) => `'${file.name}'`).join(', ')}`
40+
}
41+
]
42+
};
43+
}
44+
return { contents: input?.content, loader: 'text' };
45+
});
3246
build.onLoad({ filter: /^\/runtime\/v1\/.*.css$/, namespace: namespaces.bundle }, (args) => {
3347
return { contents: `@import "${args.path}";`, loader: 'css' };
3448
});

runtime/v1/env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ declare module '*.json' {
4444
const src: any;
4545
export default src;
4646
}
47+
48+
declare module '*?raw' {
49+
const src: string;
50+
export default src;
51+
}

0 commit comments

Comments
 (0)