简体   繁体   English

如何在反应构建中禁用Uglify

[英]How to disable Uglify in react build

I tried to use Y.js (Yjs) npm package and it works in npm start but not npm run build because Uglify doesn't support ES6. 我尝试使用Y.js(Yjs)npm包,它在npm start但不是npm run build因为Uglify不支持ES6。 So I downloaded the release of that package and include it directly. 所以我下载了该软件包的版本并直接包含它。 But my reactjs npm run build is still complaining about Uglify. 但我reactjs npm run build仍在抱怨丑化。

 Creating an optimized production build... Failed to compile. static/js/main.3d2ecf94.js from UglifyJs SyntaxError: Unexpected token: name (YArray) [./src/Pages/Collaborative/y-array/y-array.es6:12,0] 

and my webpack.config.js looks like this: 我的webpack.config.js看起来像这样:

 var path = require('path'); module.exports = { entry: path.join(__dirname, 'public', 'quickstart.js'), output: { path: '/', filename: 'bundle.js' }, module: { loaders: [ { test: /.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ["react", "es2016", "stage-2"] } }, { test: /\\.css$/, loader: "style-loader!css-loader" } ] } } 

How can I disable Uglify in my webpack? 如何在我的webpack中禁用Uglify? Which line determines that it has to Uglify in building process? 哪条线确定在构建过程中必须进行Uglify?

Edit: 编辑:

 { "name": "myCoolApps", "version": "0.1.0", "private": true, "devDependencies": { "css-loader": "^0.26.1", "react-scripts": "0.7.0", "webpack": "^1.13.3" }, "dependencies": { "ace": "git+https://github.com/ajaxorg/ace.git#master", "antd": "^2.7.2", "axios": "^0.15.3", "card": "^2.2.1", "card-react": "^1.2.6", "chat-template": "0.0.22", "codemirror": "^5.25.0", "credit-card-type": "^5.0.1", "css-loader": "^0.26.1", "d3": "^4.7.4", "firechat": "^3.0.1", "firepad": "^1.4.0", "flux": "^3.1.0", "gulp": "^3.9.1", "gulp-sass": "^3.1.0", "history": "^1.17.0", "little-loader": "^0.2.0", "lodash": "^4.17.4", "material-ui": "^0.16.6", "moment": "^2.17.1", "node-sass": "^4.5.0", "quill": "^1.2.3", "rc-calendar": "^7.6.5", "react": "^15.5.4", "react-autosuggest": "^7.0.1", "react-cookie": "^1.0.4", "react-credit-card": "^0.20.0", "react-dom": "^15.5.4", "react-dropzone": "^3.8.0", "react-event-timeline": "^1.2.2", "react-infinite": "^0.10.0", "react-infinite-scroller": "^1.0.7", "react-list": "^0.8.3", "react-notification-system": "^0.2.12", "react-router": "^3.0.0", "react-tap-event-plugin": "^2.0.1", "seedrandom": "^2.4.2", "simplewebrtc": "^2.2.2", "style-loader": "^0.13.1", "superagent": "^3.3.1", "y-array": "^10.0.6", "y-indexeddb": "^8.1.9", "y-leveldb": "0.0.1", "y-map": "^10.0.5", "y-memory": "^8.0.8", "y-richtext": "^9.0.8", "y-text": "^9.3.2", "y-webrtc": "^8.0.7", "y-websockets-client": "^8.0.15", "yjs": "^12.1.7" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } } 

Actually yea I think it uses react-script. 实际上我认为它使用react-script。 Is there anything I can do to alter that? 有什么我可以做的改变吗?

If you look at what npm run build does, it actually runs another script, react-scripts build . 如果你看看npm run build做了什么,它实际上运行另一个脚本, react-scripts build Your project is bootstrapped with create-react-app , correct? 你的项目是用create-react-app引导的, 吗?

As you can see in the package.json , you also have access to a script called eject . 正如您在package.json看到的那样,您还可以访问名为eject的脚本。

Running npm run eject will allow you to remove the app from the preconfigured workflow ( webpack , babel , etc ) and let you modify the workflow as you see fit. 运行npm run eject将允许您从预配置的工作流程( webpackbabel等)中删除应用程序,并允许您根据需要修改工作流程。

With access to the configuration files, you can add, for example, the babel uglify plugin . 通过访问配置文件,您可以添加例如babel uglify插件

But be careful, there is a trade-off. 但要小心,有一个权衡。 As the docs mention 正如文档提到的那样

If your project needs more customization, you can "eject" and customize it, but then you will need to maintain this configuration. 如果您的项目需要更多自定义,您可以“弹出”并自定义它,但是您需要维护此配置。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM