1 | # transform loader for webpack
|
2 |
|
3 | Use a browserify transforms as webpack-loader
|
4 |
|
5 | ## Usage
|
6 |
|
7 | [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
|
8 |
|
9 | Pass the module name as query parameter.
|
10 |
|
11 | ``` javascript
|
12 | var x = require("!transform?brfs!./file.js");
|
13 | var x = require("!transform/cacheable?brfs!./file.js"); // cacheable version
|
14 | ```
|
15 |
|
16 | If you pass a number instead it will take the function from `this.options.transforms[number]`.
|
17 |
|
18 | ### Example webpack config
|
19 |
|
20 | ``` javascript
|
21 | module.exports = {
|
22 | module: {
|
23 | postLoaders: [
|
24 | {
|
25 | loader: "transform?brfs"
|
26 | }
|
27 | ]
|
28 | loaders: [
|
29 | {
|
30 | test: /\.coffee$/,
|
31 | loader: "transform/cacheable?coffeeify"
|
32 | },
|
33 | {
|
34 | test: /\.weirdjs$/,
|
35 | loader: "transform?0"
|
36 | }
|
37 | ]
|
38 | },
|
39 | transforms: [
|
40 | function(file) {
|
41 | return through(function(buf) {
|
42 | this.queue(buf.split("").map(function(s) {
|
43 | return String.fromCharCode(127-s.charCodeAt(0));
|
44 | }).join(""));
|
45 | }, function() { this.queue(null); });
|
46 | }
|
47 | ]
|
48 | };
|
49 | ```
|
50 |
|
51 | ### Typical brfs Example
|
52 |
|
53 | Say you have the following Node source:
|
54 |
|
55 | ```js
|
56 | var test = require('fs').readFileSync('./test.txt', 'utf8');
|
57 | ```
|
58 |
|
59 | After `npm install transform-loader brfs --save`, add the following loader to your config:
|
60 |
|
61 | ```js
|
62 | module.exports = {
|
63 | context: __dirname,
|
64 | entry: "./index.js",
|
65 | module: {
|
66 | loaders: [
|
67 | {
|
68 | test: /\.js$/,
|
69 | loader: "transform?brfs"
|
70 | }
|
71 | ]
|
72 | }
|
73 | }
|
74 | ```
|
75 |
|
76 | The loader is applied to all JS files, which can incur a performance hit with watch tasks. So you may want to use `transform/cacheable?brfs` instead.
|
77 |
|
78 | ## License
|
79 |
|
80 | MIT (http://www.opensource.org/licenses/mit-license.php)
|