如何在反应构建中禁用Uglify

时间:2017-04-14 04:31:25

标签: javascript reactjs webpack uglifyjs

我尝试使用Y.js(Yjs)npm包,它适用于npm start但不适用npm run build,因为Uglify不支持ES6。所以我下载了该软件包的版本并直接包含它。但是我的reactjs npm run build仍在抱怨Uglify。



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]




我的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" }
    ]
  }
}




如何在我的网络包中禁用Uglify?哪一行确定在构建过程中必须进行Uglify?

修改



{
  "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"
  }
}




实际上我认为它使用的是反应脚本。我能做些什么来改变它吗?

1 个答案:

答案 0 :(得分:2)

如果您查看npm run build的作用,它实际上会运行另一个脚本react-scripts build。您的项目是使用create-react-app引导的,对吗?

正如您在package.json中所看到的,您还可以访问名为eject的脚本。

运行npm run eject将允许您从预配置的工作流程(webpackbabel等)中删除该应用,并允许您根据需要修改工作流程。

通过访问配置文件,您可以添加babel uglify plugin

但要小心,有一个权衡。正如文档中提到的那样

  

如果您的项目需要更多自定义,您可以"弹出"并自定义它,但您需要维护此配置。