Babel-plugin-module-resolver: resolve module.hot.accept

Created on 17 May 2017  路  9Comments  路  Source: tleunen/babel-plugin-module-resolver

It would be nice to also resolve module.hot.accept as well, in order to keep paths consistent.

Perhaps have a config option to list functions to transform, assuming the first argument is the path.

Most helpful comment

@tleunen Thanks! It works out great!

For anyone else curious, use transformFunctions, not the transformedMethods from that earlier example:

["module-resolver", {
  "transformFunctions": [
    "module.hot.accept"
  ]
}]

All 9 comments

@tleunen I think this is the right time to add an option for custom methods. Or is it a popular one and should be hardcoded?

@lukescott Correct me if I'm wrong, but this seems to be only used in Webpack v1, that is deprecated? If so, then I'm even more convinced this should be done as a separate option. Will prepare the feature soon.

The config would look like this:

["module-resolver", {
  "transformedMethods": [
    "module.hot.accept"
  ]
}]

I'm using webpack 2. I wouldn't think it would be as it is essential in cases where you need to run additional code. For example, with Redux:

export default function configureStore(state) {
    const store = createStore(reducer, state, devToolsEnhancer())
    if (module.hot) {
        module.hot.accept("./reducer", () => {
            store.replaceReducer(require("./reducer").default)
        })
    }
    return store
}

The only thing that's new in webpack 2 (that I'm aware of) is module support, which allows you to do:

export default function configureStore(state) {
    const store = createStore(reducer, state, devToolsEnhancer())
    if (module.hot) {
        module.hot.accept("./reducer", () => {
            store.replaceReducer(reducer) // <--- reducer gets replaced by webpack
        })
    }
    return store
}

That's assuming you've turned off module support in babel and use webpack's module system.

Config option looks good though 馃憤

I'm closing the issue. We merged the PR that adds the functionality for you to add module.hot.accept as one of the function to transform.

I'd like to make a triage again of the open issues and see what we can do before releasing a new version, and hopefully release it for good this weekend/early next week.

@tleunen Is there a chance for a new release soon? I'd really like to take advantage of that transformFunctions option!

Hi @vdh,
yes, I took a break of my OSS. I'll try to get back on this project this weekend and see what should be done before releasing, probably Sunday.

From what I remember, we have to fix the eslint integration, but we might have a few other things too.

Thanks

Hey @vdh I've released [email protected]. Please use it alongside [email protected] to make sure your linting still works as expected :)

@tleunen Thanks! It works out great!

For anyone else curious, use transformFunctions, not the transformedMethods from that earlier example:

["module-resolver", {
  "transformFunctions": [
    "module.hot.accept"
  ]
}]
Was this page helpful?
0 / 5 - 0 ratings