简体   繁体   English

如何在 React 和 JSX 中导入名称中带有特殊字符的 JS 文件?

[英]How can I import a JS file with special characters in it's name in React and JSX?

How can I import a JS file with special characters in it's name in React and JSX?如何在 React 和 JSX 中导入名称中带有特殊字符的 JS 文件?

I can我可以

import { tomorrow} from 'react-syntax-highlighter/dist/esm/styles/hljs';

(the folder contains tomorrow.js and tomrorrow-night.js) (该文件夹包含明天.js 和 tomrorrow-night.js)

but I can't:但我不能:

import { tomorrow-night} from 'react-syntax-highlighter/dist/esm/styles/hljs';

I don't think destructuring works here because it's an import statement.我认为解构在这里不起作用,因为它是一个导入语句。

you can try as你可以试试

import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';

const TomorrowNight = Highlighter[`tomorrow-night`];

How about using the import * as blah import?使用import * as blah import 怎么样? That gives you an object that you can then lookup any string in.这为您提供了一个对象,然后您可以在其中查找任何字符串。

import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM