Skip to content

Commit

Permalink
Add support for explicit loader chains in extracted files
Browse files Browse the repository at this point in the history
  • Loading branch information
benurb committed May 23, 2017
1 parent a753af0 commit e7e361e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/extractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ function extractLoader(content) {
this.addDependency(absPath);

// If the required file is a JS-file, we just evaluate it with node's require
// This is necessary because of the css-loader which uses a helper module (css-base.js) to export stuff
if (/css-base\.js$/i.test(resourcePath)) {
// This is necessary because of the css-loader which uses a helper module (css-base.js) to export stuff.
// If the required file should be processed by a loader we do not touch it (even if it is a .js file).
if (/^[^!]*css-base\.js$/i.test(resourcePath)) {
return require(absPath);
}

Expand Down
9 changes: 9 additions & 0 deletions test/extractLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ describe("extractLoader", () => {
expect(imgHtml).to.have.content.that.match(/<img src="\/other\/hi-dist\.jpg">/);
})
);
it("should support explicit loader chains", () => {
return compile({ testModule: "loader.html" }).then(() => {
const loaderHtml = path.resolve(__dirname, "dist/loader-dist.html");
const errJs = path.resolve(__dirname, "dist/err.js");

expect(loaderHtml).to.be.a.file();
expect(errJs).to.have.content("this is a syntax error\n");
});
});
it("should report syntax errors", () =>
compile({ testModule: "error.js" }).then(
() => { throw new Error("Did not throw expected error"); },
Expand Down
10 changes: 10 additions & 0 deletions test/modules/loader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<script src="${require('!!file?name=err.js!./error.js')}"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion test/support/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default function ({ testModule, publicPath, query = "" }) {
"file?name=[name]-dist.[ext]",
path.resolve(__dirname, "../../lib/extractLoader.js") + query,
"html?" + JSON.stringify({
attrs: ["img:src", "link:href"]
attrs: ["img:src", "link:href"],
interpolate: true
})
]
},
Expand Down

0 comments on commit e7e361e

Please sign in to comment.