problem description
A js tool project. has multiple directories . After deployment, the address is provided for others to call. However, some api API addresses in the project are different in different development, testing and production environments, so you want to replace them with webpack"s define plug-in after each environment is configured.
what I expect is that only wants to replace configuration items and compress js, and css, does not package .
the environmental background of the problems and what methods you have tried
during the research, only the define replacement of a single file was tried, and there was no problem. When applied to the project, it is found that entry can be generated through glob, but it will be packaged during compilation, so some Module not found, cannot continue.
related codes
/ / Please paste the code text below (do not replace the code with pictures)
//entries
var entries= function () {
var srcDir = resolve("/src/")
var entryFiles = glob.sync(srcDir + "**/*.js")
var map = {};
for (var i = 0; i < entryFiles.length; iPP) {
var filePath = entryFiles[i];
var filename = filePath.substring(filePath.lastIndexOf("\/") + 1, filePath.lastIndexOf("."));
map[filename] = filePath;
}
console.log(map)
return map;
}
// define
new webpack.DefinePlugin(function () {
let obj = {}
for (let key in config) {
obj["envConfig." + key] = config[key]
}
return obj
}())
what result do you expect?
I don"t know if there is any plan to realize my expectations. I hope all experienced bosses can give me a helping hand. Thank you!