Skip to content

Commit b2f6c73

Browse files
committed
update deps, add _jsSource raw source passthrough
1 parent 6ec5b14 commit b2f6c73

File tree

5 files changed

+4510
-7
lines changed

5 files changed

+4510
-7
lines changed

.npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
src
21
test
32
contributing.md
43
.editorconfig
54
.travis.yml
65
.nyc_output
6+
yarn.lock

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Just load it up in your webpack config like this:
2222
module.exports = {
2323
module: {
2424
loaders: [
25-
{ test: /\.foo$/, loader: 'source' }
25+
{ test: /\.foo$/, loader: 'source-loader' }
2626
]
2727
}
2828
}
@@ -39,7 +39,9 @@ As an added bonus, this loader makes the buffered raw source available on the `l
3939

4040
Let's break down how this could be done. Inside any plugin hook, you have a `compilation` object. You can get the `loaderContext` for any of the modules that webpack is processing through `compilation.modules` -- just find the one(s) you want by name. Now you have a large object which is an instance of the `DependenciesBlock` class, with a bunch of great information on it. You can find the raw buffered source under the `_src` property if the file was loaded with the source-loader.
4141

42-
Wondering what sets this loader apart from [raw-loader](https://github.com/webpack/raw-loader)? This is it. Both loaders expose the file's contents to be required by webpack, but this loader also exposes the raw source for plugin processing. It also does not try to stringify binary files (which can cause bugs), has tests, and is actively maintained, as a bonus.
42+
Additionally, if you have a specific source that is valid javascript and you'd like this loader not to output it as a string that would need to be eval'd in order to use the javascript, there's a hack for that. Within a plugin or another loader, if you add `_jsSource` as a truthy property to the module, it will skip the extra stringification and output the source raw. Note that you will get an error if it's not valid javascript, so make sure you are only setting the `_jsSource` property if you are positive that what is coming out of your loader chain is going to be js. To set from a loader, `this._module._jsSource = true` will do it, and from a plugin, you can do the same as is described above with the `_src` property.
43+
44+
Wondering what sets this loader apart from [raw-loader](https://github.com/webpack/raw-loader)? This is it. Both loaders expose the file's contents to be required by webpack, but this loader also exposes the raw source for plugin processing, and allows raw js to be passed through conditionally. It also does not try to stringify binary files (which can cause bugs), has tests, and is actively maintained, as a bonus.
4345

4446
### License & Contributing
4547

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function (source) {
1010
if (isBinaryPath(path)) {
1111
src += '"binary"'
1212
} else {
13-
src += JSON.stringify(String(source))
13+
src += this._module._jsSource ? String(source) : JSON.stringify(String(source))
1414
}
1515
return src
1616
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
},
99
"bugs": "https://github.com/static-dev/source-loader/issues",
1010
"devDependencies": {
11-
"ava": "^0.19.0",
11+
"ava": "^0.21.0",
1212
"coveralls": "2.x",
13-
"nyc": "10.2.0",
14-
"standard": "10.0.0",
13+
"nyc": "^11.0.3",
14+
"standard": "^10.0.2",
1515
"webpack": "^3.0.0"
1616
},
1717
"engines": {

0 commit comments

Comments
 (0)