您当前正在使用NODE_ENV === > 'production'之外的缩小代码



"您当前正在使用NODE_ENV之外的缩小代码 === "生产"。这意味着您正在运行较慢的开发速度 Redux 的构建。你可以使用松散的环境 (https://github.com/zertosh/loose-envify( 用于浏览器化或 DefinePlugin for webpack (http://stackoverflow.com/questions/30030031( 以确保您拥有适用于生产构建的正确代码。

当我尝试在 react native 中运行我的应用程序时,我收到此错误,我不知道如何解决此错误,并且我已经在谷歌中搜索了解决方案。 但我仍然收到此错误

我遇到了同样的问题。如果您使用 expo 创建 react 原生应用程序,请检查.expo 文件夹在 settings.json 中:

{ 
  //you should have setted 
  minified: false,
  //when is 
  dev: true
}

解决了我的问题

您可以将此配置添加到 webpack.config,js 以暂时摆脱此警告,

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

脚本中定义节点环境。 基于此,您可以打开插件

例如,在开发中,您不需要缩小代码。 但在生产中应该缩小它。 而且您在生产中不需要热加载器,反之亦然。 因此,最好定义节点 ENV 变量并基于它进行切换。

这就是你定义它的方式。

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

基于此环境,您可以拥有更多/更少的插件来操作您的代码库这是我基于 env 的常见 webpackconfig。

下面是我的 Reactjs 配置条件检查。 您可以将 simler 概念应用于本机

const env=process.env.NODE_ENV;
const isProd = (env.toLowerCase().trim()=== 'production' || env.toLowerCase().trim() === 'staging')? true: false;
if (isProd) {
 //config.plugins will have all common plugin for both dev and prod
  Array.prototype.push.apply(config.plugins, [
    new webpack.optimize.UglifyJsPlugin({ sourceMap: true }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.AggressiveMergingPlugin(),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendors',
      minChunks(module) {
        const { context } = module;
        if (typeof context !== 'string') {
          return false;
        }
        return context.indexOf('node_modules') !== -1;
      },
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'common',
      minChunks(module, count) {
        return count >= 2;
      },
    }),
    new CompressionPlugin({
      asset: '[path].gz[query]',
      algorithm: 'gzip',
      test: /.(js|html)$/,
      threshold: 10240,
      minRatio: 0.8,
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true,
      debug: false,
      noInfo: true,
      options: {
        context: './',
      },
    }),
    new HtmlWebpackPlugin({
      title: 'React App',
      filename: 'index.html',
      template: './src/index.ejs',
      favicon: './src/favicon.ico',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true,
      },
      inject: true,
    }),
  ]);
} else {
  config.entry.splice(1, 0, 'react-hot-loader/patch');
  Array.prototype.push.apply(config.plugins, [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(),
    new HtmlWebpackPlugin({
      title: 'React App',
      filename: 'index.html',
      template: './src/index.ejs',
      inject: true,
      favicon: './src/favicon.ico',
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: false,
      debug: true,
      noInfo: false,
      options: {
        context: './',
      },
    }),
  ]);
}

最新更新