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

[Feature]: keep query in resolved path #1827

Closed
hardfist opened this issue Dec 6, 2021 · 3 comments
Closed

[Feature]: keep query in resolved path #1827

hardfist opened this issue Dec 6, 2021 · 3 comments

Comments

@hardfist
Copy link
Contributor

hardfist commented Dec 6, 2021

const esbuild = require('esbuild');
const path = require('path')
async function main(){
  esbuild.build({
    entryPoints: {
      main: path.resolve('./src/index.js?entry')
    },
    plugins:[{
      name: 'xxx',
      setup(build){
        build.onLoad({filter:/.*/}, xxx => {
          console.log('resolvedId',xxx)
        })
      }
    }]
  })
}
main();

the result is

resolvedId {
  path: '/Users/yj/project/ts-demo/src/index.js', // entry query is ignored
  namespace: 'file',
  pluginData: undefined
}

if we use query to specify an virtual module which the lost query will cause an problem(like when handle vue compile)

@evanw evanw closed this as completed in 049f99c Dec 12, 2021
@hardfist
Copy link
Contributor Author

Thanks for the fix, but there's still an problem

let examplePlugin = {
  name: 'example',
  setup(build) {
    build.onResolve({ filter: /.*/ }, args => {
      return { path: args.path, suffix: '?#iefix' }
    })

    build.onLoad({ filter: /.*/ }, args => {
      console.log({ path: args.path, suffix: args.suffix })
    })
  },
}

since onLoad relys on onResolve plugin to add suffix, so we had to implement onResolve plugin ourself, which is not a trivial problem(since build.internal_resolve is not supported yet), even we may implement internal_resolve ourself, it's not efficient

@evanw
Copy link
Owner

evanw commented Dec 14, 2021

since onLoad relys on onResolve plugin to add suffix

That's not true. The built-in onResolve behavior also fills in the suffix, so your plugin does not need an onResolve callback at all to get the suffix.

@hardfist
Copy link
Contributor Author

That's great, and Previously plugins had to add their own onResolve handler if they wanted to use the query suffix this sentence might be kind of misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants