Javascript 网页包源代码映射奇怪的行为
我遇到了Webpack(4.35.2)的一个奇怪行为,在Javascript 网页包源代码映射奇怪的行为,javascript,webpack,Javascript,Webpack,我遇到了Webpack(4.35.2)的一个奇怪行为,在devtool:“sourcemap”时调用了我的函数两次 这里有一个简单的复制结构: index.js (function test() { console.log("function test"); })(); import t from "./index"; const path = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugi
devtool:“sourcemap”
时调用了我的函数两次
这里有一个简单的复制结构:
index.js
(function test() {
console.log("function test");
})();
import t from "./index";
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: {
index: "./index.js",
other: "./other.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html"
})
],
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true
}
};
other.js
(function test() {
console.log("function test");
})();
import t from "./index";
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: {
index: "./index.js",
other: "./other.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html"
})
],
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true
}
};
webpack.config.js
(function test() {
console.log("function test");
})();
import t from "./index";
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: {
index: "./index.js",
other: "./other.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html"
})
],
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true
}
};
如果运行它,test()
将被调用两次。然后将
devtool
更改为其他内容,它会被调用一次(我认为它应该被调用)
有人知道发生了什么吗