hannoeru / esbuild-plugin-raw

esbuild plugin for raw import
MIT License
16 stars 3 forks source link

Outputs full source file path #64

Closed mistic100 closed 1 year ago

mistic100 commented 1 year ago

Describe the bug

I am using this plugin to load SVG files into my lib.

When I look at the generated files I can see comments like :

// raw-loader:B:\Projects\misc\esbuild-raw\icon.svg?raw

=> the plugin is outputing the full file path into the generated files. Beside being not very clean, I think it could lead to information leak (something something about system structure on a corporate computer).

I tried to replace this line https://github.com/hannoeru/esbuild-plugin-raw/blob/1698f08e3761d7d3e9378cf837d4f6fe354d690d/src/index.ts#L11 by path: args.path and it seems to continue working without any issue and now the comment is simply

// raw-loader:./icon.svg?raw

I guess the path resolution is here to handle more complex cases, perhaps it could be done only in onLoad

Reproduction

https://github.com/mistic100/temp-esbuild-raw

System Info

Windows 10

Used Package Manager

yarn

Validations

mistic100 commented 1 year ago

Will I noticed (after reading esbuild doc) that this plugin might not be useful in many basic cases. The same result can be obtained with the loader option.

esbuild --loader:.svg=text
// tsup.config.js
export default defineConfig((options) => {
  return {
    entryPoints: ['src/index.ts'],
    esbuildPlugins: [
      // rawPlugin(),
    ],
    esbuildOptions(options, context) {
      options.loader = {
        '.svg': 'text',
      };
    },
    clean: true,
  }
});