Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

feat(conf): Adds support for webpack configurations exported as functions #54

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test/fixtures/
test/*.config.js
test/*.config.babel.js
test/*.config.babel.js
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default function({ types: t }) {
// Require the config
let conf = require(confPath);

// if the configuration expots a function, invoke it
if (typeof conf === 'function') {
conf = conf();
}

// if the object is empty, we might be in a dependency of the config - bail without warning
if (!Object.keys(conf).length) {
return;
Expand Down
8 changes: 7 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('should ignore empty object', t => {
});

test('works with webpack configs that export an array, instead of a single object (multicompile mode)', t => {
const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.js'});
const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.config.js'});
const expected = readFixture('multicompile/expected.js');
t.is(actual, expected);
});
Expand All @@ -115,3 +115,9 @@ test('doesnt output extensions when noOutputExtension is set to true', t => {
const expected = readFixture('no-extension/expected.js');
t.is(actual, expected);
});

test('works with webpack configs that export function', t => {
const actual = transformFixture('basic/absolute.js', {config: './webpack.function.config.js'});
const expected = readFixture('basic/expected.js');
t.is(actual, expected);
});
13 changes: 13 additions & 0 deletions test/webpack.function.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

var path = require('path');

module.exports = function() {
return {
resolve: {
alias: {
'my-absolute-test-lib': path.join(__dirname, 'assets/le-test-lib'),
'same-folder-lib': path.resolve(__dirname, 'fixtures/basic')
}
}
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

var path = require('path'); // eslint-disable-line no-var, import/no-commonjs
var path = require('path');

// eslint-disable-next-line import/no-commonjs
module.exports = [{
resolve: {
alias: {
Expand Down