【问题标题】:Import() and import * not working together. Node and WebpackImport() 和 import * 不能一起工作。节点和 Webpack
【发布时间】:2018-01-14 15:09:06
【问题描述】:

我正在使用这种常规设置开发一个应用程序:

babel-node -> Express 服务器 -> Webpack 中间件 -> React

我正在尝试使用 import() 实现代码拆分。这是我的 .babelrc

{
  "presets": [
    "react",
    [
      "es2015",
      {
        "loose": true,
        "modules": false
      }
    ],
    "stage-0"
  ],
  "plugins": [
    [
      "transform-runtime",
      "react-hot-loader/babel",
      "babel-plugin-syntax-dynamic-import",
      "babel-plugin-dynamic-import-webpack",
      "babel-plugin-transform-decorators-legacy",
      "babel-plugin-transform-class-properties",
      "react-intl",
      {
        "messagesDir": "./build/messages",
        "enforceDescriptions": false
      }
    ]
  ]
}

一些节点的代码使用import * from *,所以如果我删除 "modules": false 一切正常,但 Webpack 失败,因为他无法解释 import() 。否则节点会因为不理解 import * 而失败。我在这里缺少什么?

【问题讨论】:

    标签: javascript node.js webpack babeljs


    【解决方案1】:

    你不需要dynamic-import-webpack,因为 webpack v2 现在自带了。

    您似乎确实安装了babel-plugin-syntax-dynamic-import。尝试将其包含在您的 .babelrc 中,如下所示:

    {
      "presets": ["es2015"],
      "plugins": ["syntax-dynamic-import"] 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-16
      • 2021-08-01
      • 2016-11-08
      • 1970-01-01
      • 2019-05-30
      • 2017-11-26
      • 2017-07-04
      • 1970-01-01
      相关资源
      最近更新 更多