webpack-contrib / transform-loader

transform loader for webpack
MIT License
110 stars 23 forks source link

what is the point of brfs in require statement? #4

Closed mattdesl closed 10 years ago

mattdesl commented 10 years ago

I'm trying to grasp why this would be useful: var x = require("!transform?brfs!./file.js");

It seems to be the exact same as: var x = require('./file.js')

The point of using brfs is to inline a file (like text, json, image, etc) into the bundle as utf8 string or Buffer. Whereas, at least in my tests, the explicit !transform?brfs! seems to try and parse the file as JS source code, so it fails when you try to inline typical text/JSON/etc.

Maybe the docs should be updated to show a more realistic case. e.g. Setting up your webpack config so that it can consume any modules that might use brfs and fs.readFileSync.

sokra commented 10 years ago

Most loader documentation show examples with loaders inlined in require calls, because it's very simple. But in real code you would never do so (there are exceptions, i. e. bundle-loader). You would apply the loaders in your webpack.config.js.

Feel free to update the README with more realistic example in a PR.

mattdesl commented 10 years ago

Gotcha. Submitted PR