Skip to content

Commit

Permalink
fix: include matchResource in entry request
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Mar 16, 2021
1 parent 6ae4c3e commit ee411f0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 18,971 deletions.
19,012 changes: 44 additions & 18,968 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -57,7 +57,7 @@
"babel-jest": "^26.6.3",
"bootstrap": "^4.6.0",
"cross-env": "^7.0.3",
"css-loader": "^5.0.2",
"css-loader": "^5.1.3",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"es-check": "5.2.0",
Expand Down
9 changes: 7 additions & 2 deletions src/loader.js
Expand Up @@ -92,6 +92,11 @@ export function pitch(request) {

const { EntryOptionPlugin } = webpack;

let entryRequest = `!!${request}`;
if (typeof this._module.matchResource !== 'undefined') {
entryRequest = `${this._module.matchResource}!=!${entryRequest}`;
}

if (EntryOptionPlugin) {
const {
library: { EnableLibraryPlugin },
Expand All @@ -104,14 +109,14 @@ export function pitch(request) {
library: {
type: 'commonjs2',
},
import: [`!!${request}`],
import: [entryRequest],
},
});
} else {
const { LibraryTemplatePlugin, SingleEntryPlugin } = webpack;

new LibraryTemplatePlugin(null, 'commonjs2').apply(childCompiler);
new SingleEntryPlugin(this.context, `!!${request}`, pluginName).apply(
new SingleEntryPlugin(this.context, entryRequest, pluginName).apply(
childCompiler
);
}
Expand Down
3 changes: 3 additions & 0 deletions test/cases/inline-match-resource/base64-loader.js
@@ -0,0 +1,3 @@
module.exports = function base64Loader() {
return Buffer.from(this.query.slice(1), 'base64').toString('ascii');
};
2 changes: 2 additions & 0 deletions test/cases/inline-match-resource/expected/main.css
@@ -0,0 +1,2 @@
.index__foo__3o8gA { color: red; }
.index__foo__3wlgf { color: red; }
4 changes: 4 additions & 0 deletions test/cases/inline-match-resource/index.js
@@ -0,0 +1,4 @@
/* eslint-disable */

import styles from './foo.module.css!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./index.js?foo';
import styles2 from './baz.module.css!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./index.js?bar';
29 changes: 29 additions & 0 deletions test/cases/inline-match-resource/webpack.config.js
@@ -0,0 +1,29 @@
import Self from '../../../src';

module.exports = {
entry: './index.js',
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: true,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
},
],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};

0 comments on commit ee411f0

Please sign in to comment.