-
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to provide custom index.js template (#378)
New index.js generator does not cover my cases. 1. need to add `// @flow` on top of the file 2. need to use named export Both can be easily solved with indexTemplate option. ``` function indexTemplate(files) { const exportEntries = files.map(file => { const basename = path.basename(file, path.extname(file)) return `export { ${basename} } from './${basename}'` }) return '// @flow\n' + exportEntries.join('\n') } ```
- Loading branch information
Showing
7 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require('path') | ||
|
||
function indexTemplate(files) { | ||
const exportEntries = files.map(file => { | ||
const basename = path.basename(file, path.extname(file)) | ||
return `export { ${basename} } from './${basename}'` | ||
}) | ||
return exportEntries.join('\n') | ||
} | ||
|
||
module.exports = indexTemplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const indexTemplate = require('./custom-index-template.js') | ||
|
||
function template( | ||
{ template }, | ||
opts, | ||
{ imports, componentName, props, jsx, exports }, | ||
) { | ||
return template.ast`${imports} | ||
export function ${componentName}(${props}) { | ||
return ${jsx}; | ||
} | ||
` | ||
} | ||
|
||
module.exports = { | ||
template, | ||
indexTemplate, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f734dda
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: