nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
60 stars 22 forks source link

Can it be used to hook imports in react app #15

Closed re-Tick closed 2 years ago

re-Tick commented 2 years ago

Expected Behavior

Integerate it in a react app to hook axios but the logic is not being executed. Expected "in Hooks" to logged.

import Hook from "import-in-the-middle"
Hook(["axios"], (exports, name, baseDir) => {
  console.log("in hook of axios")
})
import axios from 'axios';

Actual Behavior

Nothing is logged.

Steps to Reproduce the Problem

Specifications

bengl commented 2 years ago

@re-Tick Note that the loader hook must be used, i.e. --loader=import-in-the-middle/hook.mjs. By putting your example in a file and running it with this command-line parameter, I was able to see the log message.

I'll close this, but please feel free to comment again if you think it's not yet resolved.