Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing functions option as function #651

Merged
merged 2 commits into from
Dec 17, 2018
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