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 config files to contain non-default exports #2673

Merged
merged 2 commits into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/src/run/loadConfigFile.ts
Expand Up @@ -10,6 +10,10 @@ interface NodeModuleWithCompile extends NodeModule {
_compile(code: string, filename: string): any;
}

function interopDefault<T>(ex: T): T {
return ex && typeof ex === 'object' && 'default' in ex ? (ex as any).default : ex;
}

export default function loadConfigFile(
configFile: string,
commandOptions: any = {}
Expand All @@ -33,6 +37,7 @@ export default function loadConfigFile(
}

return bundle.generate({
exports: 'named',
format: 'cjs'
});
})
Expand All @@ -49,7 +54,7 @@ export default function loadConfigFile(

delete require.cache[configFile];

return Promise.resolve(require(configFile))
return Promise.resolve(interopDefault(require(configFile)))
.then(configFileContent => {
if (typeof configFileContent === 'function') {
return configFileContent(commandOptions);
Expand Down
2 changes: 2 additions & 0 deletions test/cli/samples/config-es6/rollup.config.js
@@ -1,5 +1,7 @@
import replace from 'rollup-plugin-replace';

export const ignoresNonDefaultExports = true

export default {
input: 'main.js',
output: {
Expand Down