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

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

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

我可以

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

(该文件夹包含tomorrow.js和tomrorrow-night.js)

但我不能:

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

我认为解构在这里不起作用,因为它是一个导入语句。

你可以试试

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

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

使用 import * as blah 导入怎么样?这为您提供了一个对象,您可以在其中查找任何字符串。

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