Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页包源代码映射奇怪的行为_Javascript_Webpack - Fatal编程技术网

Javascript 网页包源代码映射奇怪的行为

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

我遇到了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-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
更改为其他内容,它会被调用一次(我认为它应该被调用)

有人知道发生了什么吗