Skip to content

Commit c74438f

Browse files
committed
Add sourceMap query
Not using the `this.sourceMap` flag because css source maps are different @see webpack/css-loader#40
1 parent 9b9af87 commit c74438f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ module.exports = function(source) {
4444
config.plugins = config.plugins || [];
4545
config.plugins.push(webpackPlugin);
4646

47-
if (this.sourceMap) {
47+
// not using the `this.sourceMap` flag because css source maps are different
48+
// @see https://github.com/webpack/css-loader/pull/40
49+
if (query.sourceMap) {
4850
config.sourceMap = {
4951
outputSourceFiles: true
5052
};

test/index.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var moveModulesDir = require("./helpers/moveModulesDir.js");
99

1010
var CR = /\r/g;
1111
var bowerComponents = path.resolve(__dirname, "./bower_components");
12+
var pathToLessLoader = path.resolve(__dirname, "../index.js");
1213

1314
describe("less-loader", function() {
1415
this.timeout(5000);
@@ -32,6 +33,7 @@ describe("less-loader", function() {
3233
test("should transform urls to files above the current directory", "folder/url-path");
3334
test("should transform urls to files above the sibling directory", "folder2/url-path");
3435
test("should generate source-map", "source-map", {
36+
query: "?sourceMap",
3537
devtool: "source-map"
3638
});
3739
it("should report error correctly", function(done) {
@@ -67,11 +69,14 @@ function tryMkdirSync(dirname) {
6769
}
6870
}
6971

70-
function test(name, id, hooks) {
72+
function test(name, id, testOptions) {
73+
testOptions = testOptions || {};
74+
testOptions.query = testOptions.query || "";
75+
7176
it(name, function (done) {
7277
var expectedCss = readCss(id);
7378
var lessFile = "raw!" +
74-
path.resolve(__dirname, "../index.js") + "!" +
79+
pathToLessLoader + testOptions.query + "!" +
7580
path.resolve(__dirname, "./less/" + id + ".less");
7681
var actualCss;
7782
var config = {
@@ -83,8 +88,7 @@ function test(name, id, hooks) {
8388
};
8489
var enhancedReq;
8590

86-
hooks = hooks || {};
87-
hooks.before && hooks.before(config);
91+
testOptions.before && testOptions.before(config);
8892

8993
enhancedReq = enhancedReqFactory(module, config);
9094

@@ -99,7 +103,7 @@ function test(name, id, hooks) {
99103
// run asynchronously
100104
webpack({
101105
entry: lessFile,
102-
devtool: hooks.devtool,
106+
devtool: testOptions.devtool,
103107
resolve: config.resolve,
104108
output: {
105109
path: __dirname + "/output",
@@ -125,9 +129,9 @@ function test(name, id, hooks) {
125129
fs.writeFileSync(__dirname + "/output/" + name + ".async.css", actualCss, "utf8");
126130
actualCss.should.eql(expectedCss);
127131

128-
hooks.after && hooks.after();
132+
testOptions.after && testOptions.after();
129133

130-
if (hooks.devtool === "sourcemap") {
134+
if (testOptions.devtool === "sourcemap") {
131135
actualMap = fs.readFileSync(__dirname + "/output/bundle.js.map", "utf8");
132136
fs.writeFileSync(__dirname + "/output/" + name + ".sync.css.map", actualMap, "utf8");
133137
actualMap = JSON.parse(actualMap);

0 commit comments

Comments
 (0)