无法将此文件中的代码缩小
我正在编写一个我想放在npm
上的JavaScript库。 我目前正在另一个项目中使用该库,我已经使用它的GitHub存储库作为依赖项添加它:
"dependencies": { // ... others "react-web-component": "LukasBombach/react-web-component", }
我也使用UglifyJsPlugin的UglifyJsPlugin
。 现在,当我想build立我的项目,我得到一个错误:
无法编译。
无法缩小此文件中的代码:
./packages/react-scripts/node_modules/react-web-component/src/index.js line 18:0
在这里阅读更多: https : //github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify
错误命令失败,退出代码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 }); }, };
在retargetEvents
和getStyleElementsFromReactWebComponentStyleLoader
里面需要有简单的module.export
命令。 你可以在这里和这里看到他们的源代码。
我已经尝试使用ES6导出/导入命令发布我的库。
我的库的完整源代码(只是这3个文件)可以在https://github.com/LukasBombach/react-web-componentfind
我find了解决scheme!
我的代码中有一些ES6特性,即foreach
操作符和速记函数语法。 更丑陋的人不接受这一点。 我需要用ES5代码取代它,现在它运作良好。