Skip to content

Commit

Permalink
fix: do not output original file path (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 authored Oct 23, 2022
1 parent 1698f08 commit c8057cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ export default function rawPlugin(): Plugin {
setup(build) {
build.onResolve({ filter: /\?raw$/ }, (args) => {
return {
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
path: args.path,
pluginData: {
isAbsolute: path.isAbsolute(args.path),
resolveDir: args.resolveDir,
},
namespace: 'raw-loader',
}
})
build.onLoad({ filter: /\?raw$/, namespace: 'raw-loader' }, async(args) => {
const fullPath = args.pluginData.isAbsolute ? args.path : path.join(args.pluginData.resolveDir, args.path);
return {
contents: await readFile(args.path.replace(/\?raw$/, '')),
contents: await readFile(fullPath.replace(/\?raw$/, '')),
loader: 'text',
}
})
Expand Down

0 comments on commit c8057cd

Please sign in to comment.