Skip to content

Commit 6c9654d

Browse files
lunelsonevilebottnawi
authored andcommitted
feat: allow passing functions option as function (#651)
1 parent 2d6045b commit 6c9654d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/normalizeOptions.js

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function normalizeOptions(loaderContext, content, webpackImporter) {
2323
const options = cloneDeep(utils.getOptions(loaderContext)) || {};
2424
const { resourcePath } = loaderContext;
2525

26+
// allow opt.functions to be configured WRT loaderContext
27+
if (typeof options.functions === 'function') {
28+
options.functions = options.functions(loaderContext);
29+
}
30+
2631
let { data } = options;
2732

2833
if (typeof options.data === 'function') {

test/index.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ implementations.forEach((implementation) => {
190190
execTest('custom-functions', {
191191
functions: customFunctions(implementation),
192192
}));
193+
it('should expose custom functions if the option is a function', () =>
194+
execTest('custom-functions', {
195+
functions: (loaderContext) => {
196+
should.exist(loaderContext);
197+
return customFunctions(implementation);
198+
},
199+
}));
193200
});
194201
describe('prepending data', () => {
195202
it('should extend the data option if present and it is string', () =>

0 commit comments

Comments
 (0)