Loader can’t modify resource type without accessing private API

Do you want to request a feature or report a bug?

What is the current behavior?
Now that webpack has the concept of module type (JSON, JS, CSS, WASM), loaders which convert resources from one type to another do not work without either requiring the end user to modify their config (i.e. for a loader that converts to JS the user must add type: 'javascript/auto' to their config) or resorting to modifying private internal webpack APIs. The former leaks internal loader implementation details onto the user and doesn’t work if the user wants to pipe the output of that loader into another, while the latter is brittle and prone to breakage in future webpack versions.

See #6572 (comment), #6586, #6725, webpack-contrib/file-loader#264, webpack-contrib/file-loader#259, webpack-contrib/bundle-loader#74

If the current behavior is a bug, please provide the steps to reproduce.
Contrived example: https://github.com/cletusw/webpack-issue-7057

What is the expected behavior?
Webpack should support loaders that convert between resource types, probably via the loader API.

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Node v8.11.0
webpack 4.5.0

Author: Fantashit

1 thought on “Loader can’t modify resource type without accessing private API

  1. Makes sense. Maybe a this.setModuleType("javascript/auto") in the loader API.

    Do you want to send a PR? Note that module type set by loader should not leak between rebuilds. It need to be reset on unbuild.

Comments are closed.