I use webpack4 and then the config folder in the project contains dev.config.json
and prod.config.json
. I want to control which configuration file is introduced through environment variables at the front end. Here"s what I"m doing right now, as follows:
in this way, it is feasible for me to practice. I want to know how webpack is compiled when it is compiled. I only see that the corresponding files are actually introduced in the compiled files. Attach the compiled code of webpack:
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar config = {};\nif (true) {\n config = __webpack_require__(/*! ./dev/config.dev.json */ \"./config/dev/config.dev.json\");\n} else {}\nexports.default = config;//-sharp sourceURL=[module]\n//-sharp sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9jb25maWcvY29uZmlnLnRzLmpzIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vLy4vY29uZmlnL2NvbmZpZy50cz9kODk3Il0sInNvdXJjZXNDb250ZW50IjpbIlwidXNlIHN0cmljdFwiO1xuXG5PYmplY3QuZGVmaW5lUHJvcGVydHkoZXhwb3J0cywgXCJfX2VzTW9kdWxlXCIsIHsgdmFsdWU6IHRydWUgfSk7XG52YXIgY29uZmlnID0ge307XG5pZiAocHJvY2Vzcy5lbnYuTk9ERV9FTlYgPT09ICdkZXZlbG9wbWVudCcpIHtcbiAgICBjb25maWcgPSByZXF1aXJlKCcuL2Rldi9jb25maWcuZGV2Lmpzb24nKTtcbn0gZWxzZSB7XG4gICAgY29uZmlnID0gcmVxdWlyZSgnLi9wcm9kL2NvbmZpZy5wcm9kLmpzb24nKTtcbn1cbmV4cG9ydHMuZGVmYXVsdCA9IGNvbmZpZzsiXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBLFNBRUE7QUFDQSIsInNvdXJjZVJvb3QiOiIifQ==\n//-sharp sourceURL=webpack-internal:///./config/config.ts\n");
/***/ }),
/***/ "./config/dev/config.dev.json":
/*!************************************!*\
!*** ./config/dev/config.dev.json ***!
\************************************/
/*! exports provided: target, default */
/***/ (function(module) {
eval("module.exports = {\"target\":\"http://192.168.2.99:8101\"};//-sharp sourceURL=[module]\n//-sharp sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9jb25maWcvZGV2L2NvbmZpZy5kZXYuanNvbi5qcyIsInNvdXJjZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZVJvb3QiOiIifQ==\n//-sharp sourceURL=webpack-internal:///./config/dev/config.dev.json\n");
/***/ }),
help me answer thank you, I do not know how to use this method to determine whether the environment variable is correct at the front end, please advise.