2017-08-14 44 views
2

我正在创作一个我想放在npm上的JavaScript库。我目前使用在其他项目库,我一直在使用它的GitHub库增加一条,作为一个依赖:无法缩小此文件中的代码

"dependencies": { 
    // ... others 
    "react-web-component": "LukasBombach/react-web-component", 
} 
我也是用的WebPack与 UglifyJsPlugin

。现在,当我想要构建我的项目时,出现错误:

Failed to compile.

Failed to minify the code from this file:

./packages/react-scripts/node_modules/react-web-component/src/index.js line 18:0

Read more here: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

error Command failed with exit code 1.

这是我的图书馆的问题。当我从我的代码(和我的代码)中删除它时,编译工作。

我想不出是什么问题,我的代码似乎很直截了当:

const ReactDOM = require('react-dom'); 
const retargetEvents = require('./retargetEvents'); 
const getStyleElementsFromReactWebComponentStyleLoader = require('./getStyleElementsFromReactWebComponentStyleLoader'); 

module.exports = { 
    create: function(app, tagName, options) { 
    const proto = Object.create(HTMLElement.prototype, { 
     attachedCallback: { 
     value: function() { 
      const shadowRoot = this.createShadowRoot(); 
      const mountPoint = document.createElement('div'); 
      getStyleElementsFromReactWebComponentStyleLoader().forEach(style => 
      shadowRoot.appendChild(style) 
     ); 
      shadowRoot.appendChild(mountPoint); 
      ReactDOM.render(app, mountPoint); 
      retargetEvents(shadowRoot); 
     }, 
     }, 
    }); 
    document.registerElement(tagName, { prototype: proto }); 
    }, 
}; 

retargetEventsgetStyleElementsFromReactWebComponentStyleLoader里面需要有简单module.export命令。你可以看到他们的源代码herehere

我已经尝试使用ES6导出/导入命令发布我的库。

我的库的完整源代码(这只是这3个文件)可以在https://github.com/LukasBombach/react-web-component

+0

你忘了添加反应标签。 –

+0

如果我理解你的意思,你的意思是我没有要求React库。这不是问题,我不需要它。 – Lukas

+0

没有。由于有反应代码,我认为反应必须做一些我不确定的事情。如果是的话,添加标签的反应将帮助你提出这个问题来反应开发者 –

回答

3

发现我找到了解决办法!

我在我的代码中有一些ES6功能,即foreach~运算符和速记函数语法。丑陋的人不接受。我需要用ES5代码取代它,现在它运行良好。