You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom imports/exports don't work in @svgr/webpack v6.2.1 like the did in v5
Bug Report
I cannot customize the exports of the resulting JavaScript/TypeScript SVGR output, regardless of any permutation of possible options/configs that may exist.
To Reproduce
Neither this:
loader: '@svgr/webpack',options: {ref: true,memo: true,babel: false,// I don't want my babel.config.js overwritten since it has better support for old browsersjsxRuntime: 'automatic',// React >= v17 doesn't need `import React from 'react'`exportType: 'named',// Try to force the React component to be exported via named `ReactComponent`// ...template(componentInfo,svgrConfig){constastBuilder=babelTemplateBuilder`${componentInfo.imports};${componentInfo.interfaces}; const ${componentInfo.componentName} = (${componentInfo.props}) => (${componentInfo.jsx} ); export default const FileUrl = '${svgrConfig.options.state.filePath}';${componentInfo.exports}; `;returnastBuilder;},}
Will work in order to get (what should obviously be the default behavior of) fixing v6's behavior to match that of the original, correct, v5 behavior of import SvgUrl, { ReactComponent as SvgComponent } from '/path/to/my-file.svg'.
Expected behavior
Users to be able to customize the exports such that they include multiple named and/or modified default exports.
e.g. I should be able to customize the template() to produce:
import SvgUrl, { ReactComponent } from 'my-file.svg'
import { SvgUrl, ReactComponent } from 'my-file.svg'
import { SvgUrl, ReactComponent, SvgFileContentsString } from 'my-file.svg'
Any other related type of import/export modification (primarily the exports).
// What I want, even implementing many parts of the docs on your website/ReadMeconstastArray=babelTemplateBuilder`${componentInfo.imports};${componentInfo.interfaces}; function ${componentInfo.componentName}(${componentInfo.props}) { return (${componentInfo.jsx} ); }${componentInfo.componentName}.displayName = '${componentInfo.componentName}';${componentInfo.exports}; // URL of the actual SVG file export const SvgUrl = SvgAssetUrl; // Add default export for ease of use export {${svgDefaultExportReactComponent ? componentInfo.componentName : 'SvgUrl'} as default, };`;returnastArray;
instead of
// What is currently my workaroundconstastArray=babelTemplateBuilder\`yourString\`;ast.push(babelTemplateBuilder('post-processing string with extra imports/exports'));`
Watch the whole app crash and burn.
How would a user do this?
template clearly doesn't work and there isn't a way to modify the componentInfo.exports array nor specify multiple exportType config entries without running your own custom AST parser and appending it to the AST output-array.
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.
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.
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.
Custom imports/exports don't work in
@svgr/webpack
v6.2.1 like the did in v5Bug Report
I cannot customize the exports of the resulting JavaScript/TypeScript SVGR output, regardless of any permutation of possible options/configs that may exist.
To Reproduce
Neither this:
Nor this:
Nor even this:
Will work in order to get (what should obviously be the default behavior of) fixing v6's behavior to match that of the original, correct, v5 behavior of
import SvgUrl, { ReactComponent as SvgComponent } from '/path/to/my-file.svg'
.Expected behavior
Users to be able to customize the exports such that they include multiple named and/or modified default exports.
e.g. I should be able to customize the
template()
to produce:import SvgUrl, { ReactComponent } from 'my-file.svg'
import { SvgUrl, ReactComponent } from 'my-file.svg'
import { SvgUrl, ReactComponent, SvgFileContentsString } from 'my-file.svg'
Link to repl or repo (highly encouraged)
import * as SvgModule from '@/assets/react_logo.svg'; console.log(SvgModule);
to src/components/Home/Home.jsx.instead of
How would a user do this?
template
clearly doesn't work and there isn't a way to modify thecomponentInfo.exports
array nor specify multipleexportType
config entries without running your own custom AST parser and appending it to the AST output-array.Environment
Related
The text was updated successfully, but these errors were encountered: