Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: deduplicate css module for @import
  • Loading branch information
fa93hws committed Jan 22, 2020
commit 82cb9397bc60141ab7388bdb8f821c827d1808d5
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ function getImportCode(
case '@import':
{
const { url, media } = item;
const preparedMedia = media ? `, ${JSON.stringify(media)}` : '';
const preparedMedia = media ? `, ${JSON.stringify(media)}` : ', ""';

if (!isUrlRequest(url)) {
codeItems.push(
`exports.push([module.id, ${JSON.stringify(
`@import url(${url});`
)}${preparedMedia}]);`
)}${preparedMedia}], true);`
);

return;
Expand Down Expand Up @@ -275,7 +275,7 @@ function getImportCode(
atRuleImportNames.set(url, importName);
}

codeItems.push(`exports.i(${importName}${preparedMedia});`);
codeItems.push(`exports.i(${importName}${preparedMedia}, true);`);
}
break;
case 'url':
Expand Down
22 changes: 21 additions & 1 deletion test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,13 @@ exports[`"modules" option should dedupe same modules in one module (issue #1037)
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../../src/runtime/api.js\\");
var ___CSS_LOADER_ICSS_IMPORT_0___ = require(\\"-!../../../../src/index.js??[ident]!./buttons/primary-button.css\\");
var ___CSS_LOADER_ICSS_IMPORT_1___ = require(\\"-!../../../../src/index.js??[ident]!./buttons/secondary-button.css\\");
var ___CSS_LOADER_AT_RULE_IMPORT_0___ = require(\\"-!../../../../src/index.js??[ident]!./colors/black.css\\");
var ___CSS_LOADER_AT_RULE_IMPORT_1___ = require(\\"-!../../../../src/index.js??[ident]!./colors/white.css\\");
exports = ___CSS_LOADER_API_IMPORT___(false);
exports.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true);
exports.i(___CSS_LOADER_AT_RULE_IMPORT_0___, \\"\\", true);
exports.i(___CSS_LOADER_AT_RULE_IMPORT_1___, \\"\\", true);
// Module
exports.push([module.id, \\".EzyG7UwnL9VTWJMm1zvyL\\\\n{\\\\n}\\\\n\\\\n.vO79o4trei2_Dt8Bi8s5W\\\\n{\\\\n}\\\\n\\", \\"\\"]);
// Exports
Expand Down Expand Up @@ -463,6 +467,22 @@ Array [
",
"",
],
Array [
"../../src/index.js?[ident]!./modules/dedupe/colors/color.css",
"
",
"",
],
Array [
"../../src/index.js?[ident]!./modules/dedupe/colors/black.css",
"",
"",
],
Array [
"../../src/index.js?[ident]!./modules/dedupe/colors/white.css",
"",
"",
],
Array [
"./modules/dedupe/source.css",
".EzyG7UwnL9VTWJMm1zvyL
Expand Down Expand Up @@ -941,7 +961,7 @@ exports.i(___CSS_LOADER_ICSS_IMPORT_3___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_4___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_5___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_6___, \\"\\", true);
exports.i(___CSS_LOADER_AT_RULE_IMPORT_0___, \\"(min-width: 100px)\\");
exports.i(___CSS_LOADER_AT_RULE_IMPORT_0___, \\"(min-width: 100px)\\", true);
var ___CSS_LOADER_URL_REPLACEMENT_0___ = ___CSS_LOADER_GET_URL_IMPORT___(___CSS_LOADER_URL_IMPORT_0___);
// Module
exports.push([module.id, \\".fSErEFKw3e7Iv0EmVr4Ii {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\";\\\\n}\\\\n\\\\n._1NrOxbibeQ5qcRoPL7kDtu {\\\\n color: blue;\\\\n}\\\\n\\\\n.djNAVB7y500wM1pkOwuGn {\\\\n display: block;\\\\n}\\\\n\\\\n._291GtMV2HIwa4Iis74myBh {\\\\n width: \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-something\\"] + \\";\\\\n}\\\\n\\\\n._2KPSOif5_L54Ue252-4SMZ {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-other\\"] + \\";\\\\n}\\\\n\\\\n._1ZuFusdyp6cE2KJ9RECux1 {\\\\n prop: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\";\\\\n duplicate: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-other\\"] + \\";\\\\n}\\\\n\\\\n.dMcylihD3G3oGCNWDsAa3 {\\\\n color: red;\\\\n}\\\\n\\\\n._2t9qA9qE4OH2A3DVwUtOFP {\\\\n color: yellow;\\\\n}\\\\n\\\\n._1XQGy4UOqsVVHSULdn-uc6 {\\\\n color: gray;\\\\n}\\\\n\\\\n._3oZRfl5v6W4ji2oerfYhpL {\\\\n color: gray;\\\\n}\\\\n\\\\n._1KLfOsDDmt6EGUIDKukOvV {\\\\n color: gainsboro;\\\\n}\\\\n\\\\n.PxB1r-csu3e3lUOZiD69t {\\\\n color: #BF4040;\\\\n}\\\\n\\\\n._2nUmv-YIlxvzza9j2rJQjJ {\\\\n color: black;\\\\n}\\\\n\\\\n@media (min-width: 960px) {\\\\n ._21OP3aGLw7Si4lLuiK3vhf {\\\\n padding: 0 20px;\\\\n }\\\\n}\\\\n\\\\n.\\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"s-white\\"] + \\" {\\\\n color: white;\\\\n}\\\\n\\\\n@media \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"m-small\\"] + \\" {\\\\n ._21OP3aGLw7Si4lLuiK3vhf {\\\\n padding: 20px 20px;\\\\n }\\\\n}\\\\n@value v-comment: /* comment */;\\\\n\\\\n.zbowt65f4EBNzWh_uiPv0 {\\\\n v-ident: validIdent;\\\\n v-pre-defined-ident: left;\\\\n v-string: 'content';\\\\n v-string-1: '';\\\\n v-url: url(https://www.exammple.com/images/my-background.png);\\\\n v-url-1: url('https://www.exammple.com/images/my-background.png');\\\\n v-url-2: url(\\\\\\"https://www.exammple.com/images/my-background.png\\\\\\");\\\\n v-integer: 100;\\\\n v-integer-1: -100;\\\\n v-integer-2: +100;\\\\n v-number: .60;\\\\n v-number-1: -456.8;\\\\n v-number-2: -3.4e-2;\\\\n v-dimension: 12px;\\\\n v-percentage: 100%;\\\\n v-hex: #fff;\\\\n v-comment: v-comment 10px v-comment;\\\\n v-function: rgb(0,0,0);\\\\n v-unicode-range: U+0025-00FF;\\\\n mutliple: #fff .60 100%;\\\\n}\\\\n\\\\n\\\\na {\\\\n content: 'content';\\\\n}\\\\n\\\\n@supports (content: 'content') {\\\\n a {\\\\n content: 'content';\\\\n }\\\\n}\\\\n\\\\n[class~='content'] {\\\\n color:green;\\\\n}\\\\n\\\\n._3yApLlXpoidfnd3JfO_WEf {\\\\n background: url(\\" + ___CSS_LOADER_URL_REPLACEMENT_0___ + \\");\\\\n}\\\\n\\", \\"\\"]);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/modules/dedupe/colors/black.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value myBlack from './color.css';
2 changes: 2 additions & 0 deletions test/fixtures/modules/dedupe/colors/color.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@value myBlack: #000000;
@value myWhite: #ffffff;
1 change: 1 addition & 0 deletions test/fixtures/modules/dedupe/colors/white.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value myWhite from './color.css';
3 changes: 3 additions & 0 deletions test/fixtures/modules/dedupe/source.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@import './colors/black.css';
@import './colors/white.css';

.nextButton
{
composes:primaryButton from './buttons/primary-button.css';
Expand Down