Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serializing big strings in sourceMap #665

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"bootstrap": "^4.5.3",
"cross-env": "^7.0.2",
"css-loader": "^5.0.1",
"del": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class MiniCssExtractPlugin {
new SourceMapSource(
content,
m.readableIdentifier(requestShortener),
m.sourceMap
m.sourceMap.toString()
)
);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export function pitch(request) {
context: module.context,
content: Buffer.from(content),
media,
sourceMap,
sourceMap: sourceMap
? Buffer.from(JSON.stringify(sourceMap))
: // eslint-disable-next-line no-undefined
undefined,
};
});
}
Expand Down
4 changes: 4 additions & 0 deletions test/TestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ describe('TestCases', () => {
if (!/^(\.|_)/.test(directory)) {
// eslint-disable-next-line no-loop-func
it(`${directory} should compile to the expected result`, (done) => {
if (directory === 'serializingBigStrings') {
clearDirectory(path.resolve(__dirname, '../node_modules/.cache'));
}

const directoryForCase = path.resolve(casesDirectory, directory);
const outputDirectoryForCase = path.resolve(outputDirectory, directory);
// eslint-disable-next-line import/no-dynamic-require, global-require
Expand Down
35 changes: 35 additions & 0 deletions test/cases/serializingBigStrings/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Self from '../../../src/index';

module.exports = {
cache: { type: 'filesystem' },
entry: 'bootstrap/dist/css/bootstrap.css',
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
],
},
],
},

plugins: [
new Self(),
{
apply(compiler) {
compiler.hooks.infrastructureLog.tap('test', (origin, type, args) => {
if (type === 'warn' || type === 'error') {
throw new Error(`<${type}> [${origin}] ${args.toString()}`);
}
});
},
},
],
};