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

Example of using custom index.js template #386

Closed
kelly-tock opened this issue Jan 20, 2020 · 6 comments
Closed

Example of using custom index.js template #386

kelly-tock opened this issue Jan 20, 2020 · 6 comments
Labels

Comments

@kelly-tock
Copy link

💬 Questions and Help

SVGR project is young, but please before asking your question:

  • Read carefully the README of the project
  • Search if your answer has already been answered in old issues

After you can submit your question and we will be happy to help you!

I see there is an option to use a custom index.js template, but reading through the code, i'm not quite sure how to do that with the CLI. The code looks like it will call it as a function, do I need to use a svgr.config.js in order to do this instead of cli options?

@TrySound
Copy link
Contributor

@kelly-tock
Copy link
Author

Awesome this is exactly what I was looking for. Thanks!

@kelly-tock
Copy link
Author

I wonder if the docs should link to the tests as examples at a minimum for the options.

@kelly-tock
Copy link
Author

hmmm, it's not working for me.

const path = require('path');

function indexTemplate(files) {
  const exportEntries = files.map((file) => {
    console.log(file);
    const basename = path.basename(file, path.extname(file));
    const exportName = /^\d/.test(basename) ? `Svg${basename}` : basename;
    return `export { default as ${exportName} } from './${basename}';`;
  });
  return exportEntries.join('\n');
}

module.exports = indexTemplate;

i'm just trying to add a semicolon to the end of the exports 😢

script in package.json:

"icons": "npx svgr --ext "tsx" --template ./materialsvgrtemplate.tsx --index-template ./indextemplate.ts --out-dir dashboard/src/js/ui/icons --icon --replace-attr-values "#506482=currentColor" dashboard/src/custom-material-icons",

@kelly-tock
Copy link
Author

my bad, my cli was out of date by just a tiny bit!

@stale
Copy link

stale bot commented Mar 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants