sorrycc / roadhog

🐷 Cli tool for creating react apps, configurable version of create-react-app.
2.72k stars 341 forks source link

配置 externals 出错 #824

Open liangxinwei opened 6 years ago

liangxinwei commented 6 years ago

我的配置:

<script crossorigin src="https://cdn.bootcss.com/d3/3.5.17/d3.min.js"></script>
 <script crossorigin src="https://cdn.bootcss.com/cal-heatmap/3.6.2/cal-heatmap.min.js"></script>
  <script crossorigin src="https://cdn.bootcss.com/d3/3.5.17/d3.min.js"></script>
  <script crossorigin src="https://cdn.bootcss.com/cal-heatmap/3.6.2/cal-heatmap.min.js"></script>
  <script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
  <script crossorigin src="https://cdn.bootcss.com/lodash.js/4.17.11/lodash.min.js"></script>
"externals": {
    react: {
      root: 'React',
      var: 'React',
      commonjs: 'react',
      commonjs2: 'react',
      amd: 'react',
    },
    'react-dom': {
      root: 'ReactDOM',
      var: 'ReactDOM',
      commonjs: 'react-dom',
      commonjs2: 'react-dom',
      amd: 'react-dom',
    },
    "lodash": "lodash",
    "moment": "moment",
    "d3": "d3",
    "cal-heatmap": "CalHeatMap",
    "g2": "G2",
    "g-cloud": "Cloud",
    "g2-plugin-slider": "G2.Plugin.slider"
  }

会报以下错误:

dynamic.js?be31:67 Uncaught TypeError: _this.load is not a function
    at new DynamicComponent (dynamic.js?be31:67)
    at constructClassInstance (react-dom.development.js?a81f:11864)
    at updateClassComponent (react-dom.development.js?a81f:13681)
    at beginWork (react-dom.development.js?a81f:14489)
    at performUnitOfWork (react-dom.development.js?a81f:17014)
    at workLoop (react-dom.development.js?a81f:17054)
    at HTMLUnknownElement.callCallback (react-dom.development.js?a81f:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?a81f:199)
    at invokeGuardedCallback (react-dom.development.js?a81f:256)
    at replayUnitOfWork (react-dom.development.js?a81f:16366)

是我引入的方式不对吗

Oscar19921030 commented 5 years ago

我也碰到这样的问题了。。

Oscar19921030 commented 5 years ago

断点进去发现_this 对象根本没有load()方法

liangxinwei commented 5 years ago

@Oscar19921030 解决了,我基于作者的 1.3 版本重新写了个 npm 包 liangxinwei_roadhog, 这个是我的优化过程, 目前项目依赖58个,打包之后140个文件,初次打包时间为 3-4min,再次打包时间缩减到 1min 之内。

Jiiun commented 5 years ago

windows环境吗?可以试下系统自带的cmd运行npm start