2018-02-11
[2018/2/11 下午9:47:58] jiadong.yu: In webpack.dev.conf.js, there is a function in plugins called “webpack.DefinePlugin”, and when I set it like this below:
[2018/2/11 下午9:48:29] jiadong.yu: 1518356902.png
i109^pimgpsh_fullsize_distr.png
[2018/2/11 下午9:49:36] jiadong.yu: Then we can get the “dddd.aaaa” in the webpack project for example in api.js:
[2018/2/11 下午9:49:55] jiadong.yu: 1518356988.png
i110^pimgpsh_fullsize_distr.png
[2018/2/11 下午9:51:51] jiadong.yu: So we could know that when we set a “xxx.yyy” in webpack’s “webpack.DefinePlugin”,then we can get the value in a webpacked project.
[2018/2/11 下午9:54:05] jiadong.yu: We could not directly get the global“process.env” without set it in the “DefinePlugin”:
[2018/2/11 下午9:54:08] jiadong.yu: 1518357241.png
i111^pimgpsh_fullsize_distr.png
[2018/2/11 下午9:56:32] jiadong.yu: So we may make a conclusion : the “process.env” in webpack’s config file is different from the one in the packed project.
[2018/2/11 下午9:59:37] jiadong.yu: So In fact, we can rewrite the
[2018/2/11 下午9:59:41] jiadong.yu: 1518357562.png
i112^pimgpsh_fullsize_distr.png
[2018/2/11 下午10:00:00] jiadong.yu: to :
[2018/2/11 下午10:00:06] jiadong.yu: 1518357602.png
i113^pimgpsh_fullsize_distr.png[2018/2/11 下午10:01:24] jiadong.yu: and set the NODE_ENV, BASE_URL and MULTILOAN in a command line : export MULTILOAN=false && export NODE_ENV='"development"' && export BASE_URL='"http://localhost:3500"' && npm run start.
[2018/2/11 下午10:03:30] jiadong.yu: The above works. But it is not a good way with a long cmd line and there would be some thing sensitive in the global “process.env”.
[2018/2/11 下午10:11:33] jiadong.yu: In a final conclusion, for “webpack.DefinePlugin” has rewritten the process.env with“process.env = require('../config/prod.env’)”, this is why we should only add “MULTILOAN: process.env.MULTILOAN” in prod.env.js and then can we get the “MULTILOAN” by “process.env.MULTILOAN” in our project.