Skip to content

Commit

Permalink
fix: webpack inline maps should work (#406)
Browse files Browse the repository at this point in the history
Somehow this was never tested before?

Also make sure that errors from the plugin propagate correctly.
  • Loading branch information
tivac committed Feb 21, 2018
1 parent 67ed96d commit f396866
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/webpack/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ ModularCSS.prototype.apply = function(compiler) {
data.css
);

// TODO: This is hacky beyond belief...
if(this.options.map && !this.options.map.inline) {
// Write out external source map if it exists
if(data.map) {
compilation.assets[`${this.options.css}.map`] = new sources.RawSource(
data.map.toString()
);
Expand All @@ -94,6 +94,7 @@ ModularCSS.prototype.apply = function(compiler) {

return done();
})
.catch(done)
);
};

Expand Down
7 changes: 7 additions & 0 deletions packages/webpack/test/__snapshots__/webpack.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ exports[`/webpack.js should output css to disk 2`] = `

exports[`/webpack.js should output external source maps to disk 1`] = `"{\\"version\\":3,\\"sources\\":[\\"packages/webpack/test/specimens/simple.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,gDAAC;AAAD,SAAS,WAAW,EAAE\\",\\"file\\":\\"simple.css\\",\\"sourcesContent\\":[\\".wooga { color: red; }\\\\n\\"]}"`;

exports[`/webpack.js should output inline source maps 1`] = `
"/* packages/webpack/test/specimens/simple.css */
.wooga { color: red; }
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBhY2thZ2VzL3dlYnBhY2svdGVzdC9zcGVjaW1lbnMvc2ltcGxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxnREFBQztBQUFELFNBQVMsV0FBVyxFQUFFIiwiZmlsZSI6InNpbXBsZS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIud29vZ2EgeyBjb2xvcjogcmVkOyB9XG4iXX0= */"
`;

exports[`/webpack.js should output json to disk 1`] = `
"/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down
33 changes: 33 additions & 0 deletions packages/webpack/test/webpack.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-statements */
"use strict";

var fs = require("fs"),
Expand Down Expand Up @@ -92,6 +93,38 @@ describe("/webpack.js", () => {
});
});

it("should output inline source maps", (done) => {
webpack({
entry : "./packages/webpack/test/specimens/simple.js",
output : {
path : output,
filename : "./simple.js"
},
module : {
rules : [
{
test,
use
}
]
},
devtool : "source-map",
plugins : [
new Plugin({
namer,
css : "./simple.css",
map : true
})
]
}, (err, stats) => {
success(err, stats);

expect(read("simple.css")).toMatchSnapshot();

done();
});
});

it("should output external source maps to disk", (done) => {
webpack({
entry : "./packages/webpack/test/specimens/simple.js",
Expand Down

0 comments on commit f396866

Please sign in to comment.