Skip to content

Commit

Permalink
fix: classes generation for client and server bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 9, 2021
1 parent a56bd94 commit 0a4ca66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
12 changes: 1 addition & 11 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,15 @@ function defaultGetLocalIdent(
localName,
options
) {
let relativeMatchResource = "";

const { context } = options;
const { resourcePath } = loaderContext;

// eslint-disable-next-line no-underscore-dangle
if (loaderContext._module && loaderContext._module.matchResource) {
relativeMatchResource = `${normalizePath(
// eslint-disable-next-line no-underscore-dangle
path.relative(context, loaderContext._module.matchResource)
)}\x00`;
}

const relativeResourcePath = normalizePath(
path.relative(context, resourcePath)
);

// eslint-disable-next-line no-param-reassign
options.content = `${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
options.content = `${relativeResourcePath}\x00${localName}`;

let { hashFunction, hashDigest, hashDigestLength } = options;
const matches = localIdentName.match(
Expand Down
30 changes: 15 additions & 15 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -849,66 +849,66 @@ exports[`loader should work with inline module syntax: result 1`] = `
Array [
Array [
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./index-loader-syntax.modules.css",
".ABsTUeF6gmFCjdFT2gFj {
".xCJYD030P78MBXmutRe1 {
color: red;
}
._hMCVXaTnfM6PXNxIi9q {
.Ei0SB4gC2Hc256_lNm0O {
color: white;
}",
"",
],
Array [
"button.modules.css!=!./index-loader-syntax-sass.css",
".Drgxp1xjMmc3NE0RSqYo {
".sApvvu2Ofv8P96bvkTV6 {
width: 5px;
}",
"",
],
Array [
"other.modules.scss!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./index-loader-syntax-sass.modules.css",
".Bf1TxkQnV__64Gk9dM7n > .qOILSEPdF7F3GDpf9VWt {
"._ca3ww50DquZ6RvWVlGp > .KQ_jhA95rsUHVKjE6AXn {
color: red;
}",
"",
],
Array [
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax.modules.css",
".ABsTUeF6gmFCjdFT2gFj {
".xCJYD030P78MBXmutRe1 {
color: red;
}
._hMCVXaTnfM6PXNxIi9q {
.Ei0SB4gC2Hc256_lNm0O {
color: white;
}
._65OKcDrrEG8MI0jTKCQ {
.KMo3xxd4WM4PLTjhSvMc {
from: custom;
}",
"",
],
Array [
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax.modules.css",
".ABsTUeF6gmFCjdFT2gFj {
".xCJYD030P78MBXmutRe1 {
color: red;
}
._hMCVXaTnfM6PXNxIi9q {
.Ei0SB4gC2Hc256_lNm0O {
color: white;
}
._65OKcDrrEG8MI0jTKCQ {
.KMo3xxd4WM4PLTjhSvMc {
from: custom;
}",
"",
],
Array [
"other.modules.scss!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax-sass.modules.css",
".Bf1TxkQnV__64Gk9dM7n > .qOILSEPdF7F3GDpf9VWt {
"._ca3ww50DquZ6RvWVlGp > .KQ_jhA95rsUHVKjE6AXn {
color: red;
}
.iCwSzW_a1wp1hr9lXhSh {
.zeG_Xwa9FzgAQ_wrfP67 {
from: custom;
}",
"",
Expand All @@ -922,21 +922,21 @@ Array [
],
Array [
"button.modules.css!=!./index-loader-syntax-sass.css",
".Drgxp1xjMmc3NE0RSqYo {
".sApvvu2Ofv8P96bvkTV6 {
width: 5px;
}",
"",
],
Array [
"button.module.scss!=!./base64-loader/index.js?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=bar",
"._fj422pJ2ianfug99ZY_ {
".RK1MI2vvw75Y7ERMcD0r {
color: red;
}",
"",
],
Array [
"other.module.scss!=!./base64-loader/index.js?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=baz",
".KvYw79kUeYHQWQPScCTK {
".RK1MI2vvw75Y7ERMcD0r {
color: red;
}",
"",
Expand Down
14 changes: 7 additions & 7 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5079,11 +5079,11 @@ import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../src/runtime/noSour
import ___CSS_LOADER_API_IMPORT___ from \\"../../src/runtime/api.js\\";
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
// Module
___CSS_LOADER_EXPORT___.push([module.id, \\".tAbfDoQYh1hH8fgy5jt_ {\\\\n color: red;\\\\n}\\\\n\\\\n._h7REYQFFxfq7wKBe15e { from: custom; }\\", \\"\\"]);
___CSS_LOADER_EXPORT___.push([module.id, \\"._LAQzblHTRmSe8Mk9eNB {\\\\n color: red;\\\\n}\\\\n\\\\n.Lc8lLgBO3fED_ZtsON9I { from: custom; }\\", \\"\\"]);
// Exports
___CSS_LOADER_EXPORT___.locals = {
\\"some-class\\": \\"tAbfDoQYh1hH8fgy5jt_\\",
\\"class\\": \\"_h7REYQFFxfq7wKBe15e\\"
\\"some-class\\": \\"_LAQzblHTRmSe8Mk9eNB\\",
\\"class\\": \\"Lc8lLgBO3fED_ZtsON9I\\"
};
export default ___CSS_LOADER_EXPORT___;
"
Expand Down Expand Up @@ -5118,11 +5118,11 @@ Array [
],
Array [
"other.modules.css!=!./my-inline-loader/index.js!./simple.css",
".tAbfDoQYh1hH8fgy5jt_ {
"._LAQzblHTRmSe8Mk9eNB {
color: red;
}

._h7REYQFFxfq7wKBe15e { from: custom; }",
.Lc8lLgBO3fED_ZtsON9I { from: custom; }",
"",
],
Array [
Expand Down Expand Up @@ -15191,7 +15191,7 @@ exports[`"modules" option should work with the 'auto' and exctract CSS using min
"/*!*****************************************************************!*\\\\
!*** css ../../src/index.js!./modules/mode/relative.module.css ***!
\\\\*****************************************************************/
.IU1H9vP4cpzQT_RvUQ84 {
._wr0eVpMbaGr94MKhByE {
color: red;
}

Expand All @@ -15202,7 +15202,7 @@ exports[`"modules" option should work with the 'auto' and exctract CSS using min

exports[`"modules" option should work with the 'auto' and exctract CSS using mini-css-extract-plugin: module 1`] = `
"// extracted by mini-css-extract-plugin
export default {\\"relative\\":\\"IU1H9vP4cpzQT_RvUQ84\\"};"
export default {\\"relative\\":\\"_wr0eVpMbaGr94MKhByE\\"};"
`;

exports[`"modules" option should work with the 'auto' and exctract CSS using mini-css-extract-plugin: warnings 1`] = `Array []`;
Expand Down

0 comments on commit 0a4ca66

Please sign in to comment.