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: v3.3.1
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: v3.3.2
Choose a head ref
  • 2 commits
  • 18 files changed
  • 1 contributor

Commits on Dec 12, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1fb5134 View commit details
  2. chore(release): 3.3.2

    alexander-akait committed Dec 12, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b3477a0 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.

### [3.3.2](https://github.com/webpack-contrib/css-loader/compare/v3.3.1...v3.3.2) (2019-12-12)


### Bug Fixes

* logic for order and media queries for imports ([1fb5134](https://github.com/webpack-contrib/css-loader/commit/1fb51340a7719b6f5b517cb71ea85ec5d45c1199))

### [3.3.1](https://github.com/webpack-contrib/css-loader/compare/v3.3.0...v3.3.1) (2019-12-12)


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": "3.3.1",
"version": "3.3.2",
"description": "css loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/css-loader",
31 changes: 8 additions & 23 deletions src/runtime/api.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);

if (item[2]) {
return `@media ${item[2]}{${content}}`;
return `@media ${item[2]} {${content}}`;
}

return content;
@@ -28,33 +28,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}

const alreadyImportedModules = {};

for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];

if (id != null) {
alreadyImportedModules[id] = true;
}
}

for (let i = 0; i < modules.length; i++) {
const item = modules[i];
const item = [].concat(modules[i]);

// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = `(${item[2]}) and (${mediaQuery})`;
} else {
item[2] = `${mediaQuery} and ${item[2]}`;
}

list.push(item);
}

list.push(item);
}
};

517 changes: 479 additions & 38 deletions test/__snapshots__/import-option.test.js.snap

Large diffs are not rendered by default.

198 changes: 54 additions & 144 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -31,33 +31,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
@@ -322,7 +307,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -337,33 +322,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
@@ -652,7 +622,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -667,33 +637,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
@@ -958,7 +913,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -973,33 +928,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
@@ -1428,7 +1368,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -1443,33 +1383,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
@@ -1708,7 +1633,7 @@ module.exports = function(useSourceMap) {
const content = cssWithMappingToString(item, useSourceMap);
if (item[2]) {
return \`@media \${item[2]}{\${content}}\`;
return \`@media \${item[2]} {\${content}}\`;
}
return content;
@@ -1723,33 +1648,18 @@ module.exports = function(useSourceMap) {
modules = [[null, modules, '']];
}
const alreadyImportedModules = {};
for (let i = 0; i < this.length; i++) {
// eslint-disable-next-line prefer-destructuring
const id = this[i][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
for (let i = 0; i < modules.length; i++) {
const item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
const item = [].concat(modules[i]);
if (mediaQuery) {
if (!item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = \`(\${item[2]}) and (\${mediaQuery})\`;
} else {
item[2] = \`\${mediaQuery} and \${item[2]}\`;
}
list.push(item);
}
list.push(item);
}
};
16 changes: 8 additions & 8 deletions test/fixtures/import/import.css
Original file line number Diff line number Diff line change
@@ -22,19 +22,19 @@
@import url();
@import url('');
@import url("");
@import url(test.css) screen and print;
@import url(test.css) SCREEN AND PRINT;
@import url(test.css)screen and print;
@import url(test.css) screen and print;
@import url(test-media.css) screen and print;
@import url(test.css) screen and (orientation:landscape);
@import url(test.css) SCREEN AND (ORIENTATION: LANDSCAPE);
@import url(test.css)screen and (orientation:landscape);
@import url(test.css) screen and (orientation:landscape);
@import url(test-media.css) screen and (orientation:landscape);
@import url(test-other.css) (min-width: 100px);
@import url(http://example.com/style.css);
@import url(http://example.com/style.css);
@import url(http://example.com/style.css#hash);
@import url(http://example.com/style.css?#hash);
@import url(http://example.com/style.css?foo=bar#hash);
@import url(http://example.com/other-style.css) screen and print;
@import url(http://example.com/other-style.css) screen and print;
@import url(http://example.com/other-style.css) screen and (orientation:landscape);
@import url(http://example.com/other-style.css) screen and (orientation:landscape);
@import url("//example.com/style.css");
@import url(~package/test.css);
@import ;
@@ -43,7 +43,7 @@
@import url('http://') :root {}
@import url('query.css?foo=1&bar=1');
@import url('other-query.css?foo=1&bar=1#hash');
@import url('other-query.css?foo=1&bar=1#hash') screen and print;
@import url('other-query.css?foo=1&bar=1#hash') screen and (orientation:landscape);
@import url('https://fonts.googleapis.com/css?family=Roboto');
@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC');
@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto');
4 changes: 2 additions & 2 deletions test/fixtures/import/order-1.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
div {
background: red;
.order-1 {
color: red;
}
4 changes: 2 additions & 2 deletions test/fixtures/import/order-2.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
div {
background: blue;
.order-1 {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/import/order-3-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.order-3-1 {
color: white;
}
5 changes: 5 additions & 0 deletions test/fixtures/import/order-3.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import url('./order-3-1.css') screen and (orientation:landscape);

.order-3 {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/import/order-4-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.order-4-1 {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/import/order-4-2-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.order-4-2-1 {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/import/order-4-2-2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.order-4-2-2 {
color: red;
}
6 changes: 6 additions & 0 deletions test/fixtures/import/order-4-2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import url('./order-4-2-1.css');
@import url('./order-4-2-2.css') (orientation:landscape);

.order-4-2 {
color: red;
}
6 changes: 6 additions & 0 deletions test/fixtures/import/order-4.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import url('./order-4-1.css') (min-width: 1000px);
@import url('./order-4-2.css') (min-width: 2000px);

.order-4 {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/import/order.css
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
@import url(http://example.com/style.css);
@import url('./order-2.css') screen and (min-width: 2000px);
@import url(http://example.com/style.css);
@import url('./order-3.css');
@import url(http://example.com/style.css);
@import url('./order-4.css') screen;

div {
width: 100%;
6 changes: 3 additions & 3 deletions test/runtime/__snapshots__/api.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`api should import modules 1`] = `"body { b: 2; }body { c: 3; }@media print{body { d: 4; }}@media screen{body { a: 1; }}"`;
exports[`api should import modules 1`] = `"body { b: 2; }body { c: 3; }body { b: 2; }@media print {body { b: 2; }}@media print {body { d: 4; }}@media screen {body { a: 1; }}"`;

exports[`api should import named modules 1`] = `"body { b: 2; }body { c: 3; }@media print{body { d: 4; }}@media screen{body { a: 1; }}"`;
exports[`api should import named modules 1`] = `"body { b: 2; }body { c: 3; }body { b: 2; }@media print {body { b: 2; }}@media print {body { d: 4; }}@media screen {body { a: 1; }}"`;

exports[`api should toString a single module 1`] = `"body { a: 1; }"`;

exports[`api should toString multiple modules 1`] = `"body { b: 2; }body { a: 1; }"`;

exports[`api should toString with media query 1`] = `"@media screen{body { a: 1; }}"`;
exports[`api should toString with media query 1`] = `"@media screen {body { a: 1; }}"`;

exports[`api should toString with source mapping 1`] = `
"body { a: 1; }