node.js - how to set enviroment variable value in pre-processor in webpack? -
i using webpack 2 , added preprocessor in it. passing node_env variable value command line. in java script able access value preprocessor condition getting failed please let me know how set argument value in preprocessor?
here config file
var debug = process.env.node_env !== "production"; var webpack = require('webpack'); var path = require('path'); module.exports = { context: path.join(__dirname, "src"), devtool: debug ? "inline-sourcemap" : null, entry: "./js/app.js", module: { loaders: [ { test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, loader: 'babel-loader!preprocess-loader?+debug', // query: { // presets: ['react', 'es2015'], // plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'], // } }, { test: /\.css$/, loader: "style-loader!css-loader!sass-loader" }, { test: /\.htm?$/, exclude: /(node_modules|bower_components)/, loader: 'preprocess-loader?+debug', } ] }, output: { path: __dirname + "/src/", filename: "demo.min.js" }, plugins: debug ? [] : [ new webpack.optimize.dedupeplugin(), new webpack.optimize.occurenceorderplugin(), new webpack.optimize.uglifyjsplugin({ mangle: false, sourcemap: false }), ], };
my app.js
//@if process.env.node_env !=='production' console.log("hi dev") console.log("environment",process.env.node_env) //@endif console.log("this working")
when saw console showing production value of process.env.node_env)
if getting failed checked exclude condition working fine
command used run npm start --env.node_env='production' please let me know how access variable in pre processor?
edit 1: mentioned can value not being set in preprocessor
edit 2: getting value undefined added answer way
"dev": "set node_env=dev && webpack-dev-server",
Comments
Post a Comment