Skip to content

Commit 87112a2

Browse files
committed
feat: onExports hook
1 parent db3911b commit 87112a2

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "css-loader",
2+
"name": "css-loader-with-hooks",
33
"version": "5.0.1",
4-
"description": "css loader module for webpack",
4+
"description": "css loader module for webpack with hooks feature",
55
"license": "MIT",
66
"repository": "webpack-contrib/css-loader",
7-
"author": "Tobias Koppers @sokra",
8-
"homepage": "https://github.com/webpack-contrib/css-loader",
9-
"bugs": "https://github.com/webpack-contrib/css-loader/issues",
7+
"author": "Dmytro Shpak",
8+
"homepage": "https://github.com/DmShpak/css-loader",
9+
"bugs": "https://github.com/DmShpak/css-loader/issues",
1010
"funding": {
1111
"type": "opencollective",
1212
"url": "https://opencollective.com/webpack"

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
getModulesPlugins,
2727
normalizeSourceMap,
2828
sort,
29+
getHooks,
2930
} from "./utils";
3031

3132
export default async function loader(content, map, meta) {
@@ -209,6 +210,7 @@ export default async function loader(content, map, meta) {
209210
}
210211
}
211212

213+
getHooks(exports, options, this);
212214
const importCode = getImportCode(imports, options);
213215
const moduleCode = getModuleCode(result, api, replacements, options, this);
214216
const exportCode = getExportCode(exports, replacements, options);

src/options.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@
143143
"esModule": {
144144
"description": "Use the ES modules syntax (https://github.com/webpack-contrib/css-loader#esmodule).",
145145
"type": "boolean"
146+
},
147+
"onExports": {
148+
"description": "Hook exports object",
149+
"instanceof": "Function"
146150
}
147151
},
148152
"type": "object"

src/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ function normalizeOptions(rawOptions, loaderContext) {
247247
: rawOptions.importLoaders,
248248
esModule:
249249
typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule,
250+
onExports:
251+
typeof rawOptions.onExports === "function"
252+
? rawOptions.onExports
253+
: undefined,
250254
};
251255
}
252256

@@ -704,6 +708,12 @@ function sort(a, b) {
704708
return a.index - b.index;
705709
}
706710

711+
function getHooks(exports, options, loaderContext) {
712+
if (options.onExports) {
713+
options.onExports(exports, loaderContext);
714+
}
715+
}
716+
707717
export {
708718
normalizeOptions,
709719
shouldUseModulesPlugins,
@@ -723,4 +733,5 @@ export {
723733
resolveRequests,
724734
isUrlRequestable,
725735
sort,
736+
getHooks,
726737
};

0 commit comments

Comments
 (0)