NODE_ENV === 'production' 之外的缩小代码.这意味着 Redux 的开发构建速度较慢 [英] Minified code outside of NODE_ENV === 'production'. This means slower development build of Redux

查看:76
本文介绍了NODE_ENV === 'production' 之外的缩小代码.这意味着 Redux 的开发构建速度较慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是完整的错误:您目前正在使用 NODE_ENV === 'production' 之外的缩小代码.这意味着您运行的是较慢的 Redux 开发版本.

我正在使用第 3 方图表库 CanvasJS,它需要访问全局范围.当我在我的任何模块中导入它时,实际代码在浏览器中似乎会中断(可能是 this 问题).

I am using a 3rd party charting library, CanvasJS, which needs access to the global scope. When I import it within any of my modules it seems the actual code breaks when in the browser (probably a this problem).

我通过使用 Webpack 解决了这个问题,并让 gulp 将 bundle.min.js 与缩小的图表库捆绑在一起.

I solved it by using Webpack, and having gulp bundle the bundle.min.js with the minified Charting library.

这很好用,直到我尝试生产版本.我认为对 CanvasJS 的引用可能在此过程中被破坏了.

This works just fine until I try a production build. I think the reference to CanvasJS may have gotten mangled in the process.

我的 Webpack.config 文件:

My Webpack.config file:

 var debug = process.env.NODE_ENV !== "production";
 var webpack = require('webpack');
 var path = require('path');

 module.exports = {
  context: path.join(__dirname, "public"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/main.js",
  resolve: {
   alias: {
    'react': 'react-lite',
    'react-dom': 'react-lite'
   }
  }, 
  module: {
  loaders: [
    {
     test: /\.jsx?$/,
     exclude: /(node_modules|bower_components)/,
     loader: 'babel-loader',
     query: {
       presets: ['react', 'es2015', 'stage-0'],
       plugins: [ 'transform-class-properties', 'transform-decorators-legacy'],
     }
   }
 ]
},
output: {
  path: __dirname + "/public/build/",
  filename: "bundle2.min.js"
},
plugins: debug ? [] : [
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.OccurenceOrderPlugin(),
  new webpack.optimize.UglifyJsPlugin(),
  //  new webpack.optimize.AggressiveMergingPlugin()
  new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};

我尝试将 CanvasJS 标记为外部,但这也不起作用.如何让 Redux 不运行缓慢",并引用全局对象?

I have tried to mark CanvasJS as External, but this did not work either. How can I get Redux to not "run slow", and have references to global objects?

推荐答案

您需要添加:

  new webpack.DefinePlugin({
    'process.env': {
      'NODE_ENV': JSON.stringify('production')
    }
  })

对于您的生产配置

这篇关于NODE_ENV === 'production' 之外的缩小代码.这意味着 Redux 的开发构建速度较慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆