Skip to content

Commit f7a5e53

Browse files
fix: serializing big strings in sourceMap (#665)
1 parent 4277d4d commit f7a5e53

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

package-lock.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
5858
"babel-eslint": "^10.1.0",
5959
"babel-jest": "^26.6.3",
60+
"bootstrap": "^4.5.3",
6061
"cross-env": "^7.0.2",
6162
"css-loader": "^5.0.1",
6263
"del": "^6.0.0",

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class MiniCssExtractPlugin {
685685
new SourceMapSource(
686686
content,
687687
m.readableIdentifier(requestShortener),
688-
m.sourceMap
688+
m.sourceMap.toString()
689689
)
690690
);
691691
} else {

src/loader.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ export function pitch(request) {
239239
context: module.context,
240240
content: Buffer.from(content),
241241
media,
242-
sourceMap,
242+
sourceMap: sourceMap
243+
? Buffer.from(JSON.stringify(sourceMap))
244+
: // eslint-disable-next-line no-undefined
245+
undefined,
243246
};
244247
});
245248
}

test/TestCases.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ describe('TestCases', () => {
9898
if (!/^(\.|_)/.test(directory)) {
9999
// eslint-disable-next-line no-loop-func
100100
it(`${directory} should compile to the expected result`, (done) => {
101+
if (directory === 'serializingBigStrings') {
102+
clearDirectory(path.resolve(__dirname, '../node_modules/.cache'));
103+
}
104+
101105
const directoryForCase = path.resolve(casesDirectory, directory);
102106
const outputDirectoryForCase = path.resolve(outputDirectory, directory);
103107
// eslint-disable-next-line import/no-dynamic-require, global-require
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Self from '../../../src/index';
2+
3+
module.exports = {
4+
cache: { type: 'filesystem' },
5+
entry: 'bootstrap/dist/css/bootstrap.css',
6+
module: {
7+
rules: [
8+
{
9+
test: /\.css$/,
10+
use: [
11+
Self.loader,
12+
{
13+
loader: 'css-loader',
14+
options: {
15+
sourceMap: true,
16+
},
17+
},
18+
],
19+
},
20+
],
21+
},
22+
23+
plugins: [
24+
new Self(),
25+
{
26+
apply(compiler) {
27+
compiler.hooks.infrastructureLog.tap('test', (origin, type, args) => {
28+
if (type === 'warn' || type === 'error') {
29+
throw new Error(`<${type}> [${origin}] ${args.toString()}`);
30+
}
31+
});
32+
},
33+
},
34+
],
35+
};

0 commit comments

Comments
 (0)