Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/css-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.2.0
Choose a base ref
...
head repository: webpack-contrib/css-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.2.1
Choose a head ref
  • 2 commits
  • 10 files changed
  • 2 contributors

Commits on Aug 6, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    24c0a12 View commit details
  2. Copy the full SHA
    33e7879 View commit details
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [4.2.1](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1) (2020-08-06)


### Bug Fixes

* regression with the `exportOnlyLocals` option, now `locals` are not exported under the `locals` name, it was big regression, we apologize for that ([24c0a12](https://github.com/webpack-contrib/css-loader/commit/24c0a122d1396c08326a24f6184f5da09cf52ccc))

## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)


2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "css-loader",
"version": "4.2.0",
"version": "4.2.1",
"description": "css loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/css-loader",
52 changes: 36 additions & 16 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -354,19 +354,25 @@ function getImportCode(imports, options) {
for (const item of imports) {
const { importName, url, icss } = item;

code += options.esModule
? icss && options.modules.namedExport
? `import ${importName}, * as ${importName}_NAMED___ from ${url};\n`
: `import ${importName} from ${url};\n`
: `var ${importName} = require(${url});\n`;
if (options.esModule) {
if (icss && options.modules.namedExport) {
code += `import ${
options.modules.exportOnlyLocals ? '' : `${importName}, `
}* as ${importName}_NAMED___ from ${url};\n`;
} else {
code += `import ${importName} from ${url};\n`;
}
} else {
code += `var ${importName} = require(${url});\n`;
}
}

return code ? `// Imports\n${code}` : '';
}

function getModuleCode(result, api, replacements, options) {
if (options.modules.exportOnlyLocals === true) {
return 'var ___CSS_LOADER_EXPORT___ = {};\n';
return '';
}

const { css, map } = result;
@@ -423,7 +429,7 @@ function dashesCamelCase(str) {
}

function getExportCode(exports, replacements, options) {
let code = '';
let code = '// Exports\n';
let localsCode = '';

const addExportToLocalsCode = (name, value) => {
@@ -483,13 +489,17 @@ function getExportCode(exports, replacements, options) {
if (localName) {
const { importName } = item;

localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () =>
options.modules.namedExport
? `" + ${importName}_NAMED___[${JSON.stringify(
camelCase(localName)
)}] + "`
: `" + ${importName}.locals[${JSON.stringify(localName)}] + "`
);
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
if (options.modules.namedExport) {
return `" + ${importName}_NAMED___[${JSON.stringify(
camelCase(localName)
)}] + "`;
} else if (options.modules.exportOnlyLocals) {
return `" + ${importName}[${JSON.stringify(localName)}] + "`;
}

return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
});
} else {
localsCode = localsCode.replace(
new RegExp(replacementName, 'g'),
@@ -498,17 +508,27 @@ function getExportCode(exports, replacements, options) {
}
}

if (options.modules.exportOnlyLocals) {
code += options.modules.namedExport
? localsCode
: `${
options.esModule ? 'export default' : 'module.exports ='
} {\n${localsCode}\n};\n`;

return code;
}

if (localsCode) {
code += options.modules.namedExport
? `${localsCode}`
? localsCode
: `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
}

code += `${
options.esModule ? 'export default' : 'module.exports ='
} ___CSS_LOADER_EXPORT___;\n`;

return `// Exports\n${code}`;
return code;
}

async function resolveRequests(resolve, context, possibleRequests) {
7 changes: 4 additions & 3 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -28,9 +28,10 @@ exports[`loader issue #1033 (2): warnings 1`] = `Array []`;
exports[`loader issue #1033: errors 1`] = `Array []`;

exports[`loader issue #1033: module 1`] = `
"var ___CSS_LOADER_EXPORT___ = {};
// Exports
export default ___CSS_LOADER_EXPORT___;
"// Exports
export default {
};
"
`;

Loading