我想做的是从 NextJs v13 生产构建包中排除“leaflet”和“react-leaflet”包。
我为实现这一目标所做的就是像这样修改
next.config.js
文件:
const nextConfig = {
// ...
webpack: (config, { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }) => {
config.externals = [
...config.externals,
{
"react-leaflet": "react-leaflet",
leaflet: "leaflet",
},
];
return config;
},
}
然后,基于
react-leaflet
文档(此处),我正在导入所需的组件,如下所示:
import { MapContainer } from 'https://cdn.esm.sh/react-leaflet/MapContainer'
import { TileLayer } from 'https://cdn.esm.sh/react-leaflet/TileLayer'
// And do on
但是我从 NextJs 得到的错误是:
external "https://cdn.esm.sh/react-leaflet/MapContainer"
The target environment doesn't support dynamic import() syntax so it's not possible to
use external type 'module' within a script
感谢任何帮助,因为我想减少我的 nextjs 应用程序中的包大小,因此我想从 nextjs 包中排除传单并从 c
提供它