Skip to content

Add flag enableDefaultExport for exporting as default #52

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const schema = {
description: "Disable the use of locals export. Defaults to `false`",
type: "boolean",
},
enableDefaultExport: {
description: "Enable 'export default'. Defaults to `false`.",
type: "boolean",
},
verifyOnly: {
description:
"Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`",
Expand Down Expand Up @@ -88,7 +92,8 @@ module.exports = function (content, ...args) {
const cssModuleDefinition = generateGenericExportInterface(
cssModuleKeys,
filenameToPascalCase(filename),
options.disableLocalsExport
options.disableLocalsExport,
options.enableDefaultExport
);

applyFormattingAndOptions(cssModuleDefinition, options)
Expand Down
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const filenameToTypingsFilename = (filename) => {
const generateGenericExportInterface = (
cssModuleKeys,
pascalCaseFileName,
disableLocalsExport
disableLocalsExport,
enableDefaultExport
) => {
const interfaceName = `I${pascalCaseFileName}`;
const moduleName = `${pascalCaseFileName}Module`;
Expand All @@ -75,7 +76,7 @@ ${interfaceProperties}

declare const ${moduleName}: ${namespaceName}.${interfaceName}${localsExportType};

export = ${moduleName};`;
export ${enableDefaultExport ? 'default' : '='} ${moduleName};`;
};

module.exports = {
Expand Down