Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions lib/normalizeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function normalizeOptions(loaderContext, content, webpackImporter) {
const options = cloneDeep(utils.getOptions(loaderContext)) || {};
const { resourcePath } = loaderContext;

// allow opt.functions to be configured WRT loaderContext
if (typeof options.functions === 'function') {
options.functions = options.functions(loaderContext);
}

let { data } = options;

if (typeof options.data === 'function') {
Expand Down
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ implementations.forEach((implementation) => {
execTest('custom-functions', {
functions: customFunctions(implementation),
}));
it('should expose custom functions if the option is a function', () =>
execTest('custom-functions', {
functions: (loaderContext) => {
should.exist(loaderContext);
return customFunctions(implementation);
},
}));
});
describe('prepending data', () => {
it('should extend the data option if present and it is string', () =>
Expand Down