As I have different channel to run my code in npm command.
In the npm scripts, I will write
"scripts": {
"start": "webpack-dev-server",
"start:channle_1": "CHANNEL=channe_1 webpack-dev-server",
"start:channle_2": "CHANNEL=channe_2 webpack-dev-server"
}
And in webpack.config.js, I can define variable to judge I'm in which channel.
const CHANNEL = process.env.CHANNEL || 'channe_1';
console.log('===', process.env.CHANNEL);
webpackConfig.plugins.push(
new webpack.DefinePlugin({
CHANNEL: JSON.stringify(CHANNEL),
})
);
So, in my code, there is a glable CHANNEL I can use.
But, there is a problem in my npm scripts. I want separate sever and channel.I hope it can like this
"scripts": {
"start": "webpack-dev-server",
"start:channle_1": "CHANNEL=channe_1 & npm run start",
"start:channle_2": "CHANNEL=channe_2 & npm run start"
}
As I know, & can let npm command run currently, but, in my situation, the variable CHANNEL can't pass in process.env.CHANNEL.
So, how can I solve this problem?