unjs / unplugin

Unified plugin system for Vite, Rollup, Webpack, esbuild, Rolldown, and more
https://unplugin.unjs.io
MIT License
3.02k stars 109 forks source link

Transform hook run before load hook on webpack #324

Open jzymx50 opened 1 year ago

jzymx50 commented 1 year ago

Environment

"unplugin": "^1.4.0", "webpack": "^5.88.2",

Reproduction

const unplugin = createUnplugin((options) => {
  return {
    name: 'test',
    load(id) {
      console.log(id,'load hook')
      return null
    },
    transform() {
      console.log('transform hook')
      return null
    },
    buildStart() {
      console.log('build start hook')
    }
  }
})

The console outputs are:

build start hook
transform hook
C:\xxx\src\index.js load hook

Describe the bug

From the source code, I found out the transform hook was handled before the load hook. And unshift() was used to put the generated loader into the webpack config. Should the load hook be handled earlier than the transform hook?

Additional context

No response

Logs

No response

qiYuei commented 1 year ago

I have the same question, can you tell me the answer ? please @antfu @sxzz

sxzz commented 1 year ago

Please provide a minimal reproduction. Thanks.

https://antfu.me/posts/why-reproductions-are-required