- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有下一个 Webpack.config.js:
'use strict';
const WEBPACK = require('webpack');
const PATH = require('path');
const CopyFiles = require('copy-webpack-plugin');
const BaseName = "/upct";
const CONFIG = {
resolve: {
extensions: ['', '.js', '.jsx']
},
context: __dirname,
entry: {
app: ['./src/index.jsx']
},
/*
output: {
path: PATH.join(__dirname, '/public'),
/*path: './public',*//*
publicPath: BaseName+'/',
filename: 'index.js'
},
/*
devServer: {
host: 'localhost',
port: 3000,
contentBase: PATH.join(__dirname, '/public'),
inline: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
},
*/
module: {
loaders: [
{
test: /(\.js|.jsx)$/,
loader: 'babel',
query: {
"presets": [
"es2015",
"react",
"stage-0"
],
"plugins": [
"react-html-attrs",
"transform-decorators-legacy",
"transform-class-properties"
]
}
}
]
},
plugins: [
new WEBPACK.DefinePlugin({
BASENAME: JSON.stringify(BaseName),
'process.env': {
/*'NODE_ENV': JSON.stringify(process.env.NODE_ENV)*/
'NODE_ENV': JSON.stringify('production')
}
})
]
}
if (process.env.NODE_ENV === 'production') {
CONFIG.output = {
path: PATH.join(__dirname, '/publicProduction'),
publicPath: BaseName+'/',
filename: 'index.js'
};
CONFIG.plugins.push(
new WEBPACK.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true,
warnings: false
},
comments: false
})
);
//babelSettings.plugins.push("transform-react-inline-elements");
//babelSettings.plugins.push("transform-react-constant-elements");
} else {
//CONFIG.devtool = "#cheap-module-source-map"
CONFIG.output = {
path: PATH.join(__dirname, '/publicDeveloping'),
publicPath: BaseName+'/',
filename: 'index.js'
};
CONFIG.devServer = {
host: 'localhost',
port: 3000,
contentBase: PATH.join(__dirname, '/src'),
inline: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
}
/*
CONFIG.plugins.push(
new webpack.HotModuleReplacementPlugin()
);*/
}
module.exports = CONFIG;
和下一个脚本:
"scripts": {
"build": "SET NODE_ENV='building' && webpack --progress --watch --colors",
"serve": "SET NODE_ENV='testing' && webpack-dev-server --progress --colors",
"production": "SET NODE_ENV='production' && webpack --progress -p"
},
但永远不要进入 IF (当我运行 npm run production
时),总是进入 ELSE (运行我运行的脚本)。为什么会这样? (上面我已经声明了 NODE_ENV = 'product',我不明白为什么它不起作用......)。
谢谢。
最佳答案
我以前也遇到过同样的问题。尝试先 trim 字符串,然后进行比较。
if (process.env.NODE_ENV.trim() === 'production') {
// Do Something
}
还有一件事,webpack
的 -p
标志和 SET NODE_ENV=product
基本上是同一件事,所以我不认为你两者都需要。
关于javascript - Webpack.config.js process.env.NODE_ENV 不起作用。 -ReactJS-,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43986852/
我有 an issue在生产环境中使用 webpack,我对在生产环境中运行 webpack 的不同方式感到困惑(我使用的是 Windows)。 谁能解释一下它们之间的区别: 一:命令行 webpac
我正在尝试使用 将环境变量 $NODE_ENV 设置为“生产” export NODE_ENV=production 但是当我尝试运行我的 gulp 任务时,它说变量未定义: if((process.
正如标题,我使用的是 docker ruby 2.3.5 (ubuntu) 环境,尽管我已经设置了 NODE_ENV=development,当我尝试拦截 process.env.NODE_ENV
我有一个在 Linux 上运行良好的应用程序,但是当我在 Windows 上执行它时出现此错误。 'NODE_ENV' is not recognized as an internal or exte
我想使用 webpack 制作我的应用程序的生产版本: "scripts": { "build": "webpack --mode production", }, 在我的 webpack.
这可能是一个愚蠢的问题,但我在任何地方都找不到直接答案,所以我宁愿问它,也不愿继续有这个疑问。 我正在阅读有关设置 Node 环境的信息。答案this question说我们不应该在 Node 应用程
我在我的 reactjs 解决方案中使用 gulp 并想设置 NODE_ENV,我试过这个: gulp.task('set-dev-node-env', function() { return
Python 中是否有等效的 NODE_ENV? 我想根据执行环境将 JSON 配置动态加载到 python 应用程序。在 nodeJs 中,我通过使用 process.env.NODE_ENV 来做
我正在尝试设置一个标志来通知我的代码是在生产中还是在开发中。到目前为止,我已经看到: 在 VS Code 的 launch.json 中: { "configurations": { "env": "
我正在使用 node.js 进行开发,并希望同时考虑生产和开发环境。我发现在运行 node.js 服务器时设置 NODE_ENV 可以完成这项工作。但是,当我尝试在 package.json 脚本中设
我正在尝试通过更改和测试变量 NODE_ENV 的值来实现我的代码在不同 Node.js 环境中正常工作的测试。 我一直在努力理解为什么下面的代码: process.env.NODE_ENV = un
请,这里的答案都是指一个名为 process.env.NODE_ENV 的东西,但是命令行中的 echo $process.env.NODE_ENV 不起作用。有什么想法吗? 最佳答案 使用 echo
我正在尝试为 Node.js 应用程序设置环境。但我每次都会收到这个错误。 "NODE_ENV" is not recognized as an internal or external comman
如何将 NODE_ENV 作为参数传递给 npm run 命令? 示例 package.json 文件: NODE_ENV=8080 ... "script": { "star
在我的 package.json 中,我有一个 build 脚本集来构建我的下一个项目,如下所示: "build": "echo\"$NODE_ENV\"&& NODE_ENV=$NODE_ENV n
我正在移动我的一些 firebase-queue worker 到 Firebase 函数。我用过 process.env.NODE_ENV根据我运行它们的环境为工作人员设置一些配置。有没有办法设置N
我正在使用 supertest 测试我的 API 我想检查我的 CSRF token 保护是否有效,然后在其他测试中禁用它。 为此,我设置了 NODE_ENV至 test或 not_test app.
这是我的index.js 文件: var express = require('express'); var app = express(); var compression = require('c
我想用 React 和其他代码构建我的 js 代码,并将其缩小到一个文件。 它运行良好,但我得到的是react的开发版本 看起来您正在使用 React 开发版本的缩小副本 现在我知道我需要添加NODE
每次我在配置文件中看到变量 process.env.NODE_ENV 总是困扰我,尤其是 webpack.config.js。我在哪里可以找到这个?因为有时我想将它的值更改为 production 而
我是一名优秀的程序员,十分优秀!