简体   繁体   English

动态导入使用Webpack命名导出

[英]Dynamic import named export using Webpack

Using webpack, if I want to code-split an entire module, I can change 使用webpack,如果我想代码拆分整个模块,我可以改变

import Module from 'module'

at the top of my file to 在我的文件的顶部

import('module').then(Module => {...

when I need to use the module ( docs ). 当我需要使用模块( docs )时。 Is it possible to do this but with just a single named export? 是否可以这样做,但只有一个命名导出? That is, how could I code-split the following: 也就是说,我怎么能代码拆分以下内容:

import {namedExport} from 'module'

const DynamicFoo = dynamic(import('../components/Foo').then(module => {
  const {Foo} = module
  return Foo
}));

OR 要么

import(/* webpackChunkName: "chunkName" */ '../component/Foo').then(module => {
  const {Foo} = module.default
  this.setState({ foo: Foo })
})

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

相关问题 动态import()使用webpack和babel语法错误 - Syntax Error on dynamic import() using webpack and babel 将Mediator Pattern与webpack和ES6模块一起使用导入导出 - Using Mediator Pattern with webpack and ES6 Modules import export 在将webpack与babel结合使用时,为什么使用命名导出导入默认导出会导致错误? - Why does importing a default export with a named export cause an error when using webpack with babel? 不应该在 React 中导入命名的导出 - Should not import the named export in React 如何访问通过 Webpack 动态导入 promise 导入的模块的默认导出? - How do I access the default export of a module imported via a Webpack dynamic import promise? webpack:请求的模块没有提供名为 - webpack: The requested module does not provide an export named 在Babel和Webpack中使用异步等待和动态导入语句 - Using async await and dynamic import statements with Babel and Webpack 使用ES6和let / const进行export / import和Karma / webpack-顶部导出 - Using ES6 and let/const with export / import and Karma/webpack - export at the top 当文件导入另一个命名的导出文件时,ES6动态导入失败 - ES6 Dynamic Import is failing when the file imports another named export Webpack 动态导入表达式不起作用 - Webpack Dynamic Import Expression Not Working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM