gpt4 book ai didi

javascript - 我的所有代码在由 Webpack 编译时都会运行两次

转载 作者:行者123 更新时间:2023-12-03 03:35:42 24 4
gpt4 key购买 nike

当我使用 webpack-dev-server 构建我的 js 包时,我的代码每次都会运行两次。不知道如何修复它。

Screenshot of Developer Tools console

我的 webpack 配置:

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
devtool: 'cheap-eval-sourcemap',
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/dev-server',
path.join(__dirname, '../src/main')
],
output: {
path: path.join(__dirname, '../dist'),
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, '../src/index.html')
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../assets'),
to: path.join(__dirname, '../dist/assets')
}
])
],
devServer: {
contentBase: path.join(__dirname, '../dist'),
outputPath: '/lol',
hot: true
},
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel-loader'],
include: path.join(__dirname, '../src')
}
]
}
};

最佳答案

在模板文件中,您可能手动添加了加载 bundle 。

如果你没有

inject: false 

选项

new HtmlWebpackPlugin({
template: path.join(__dirname, '../src/index.html')
}),

bundle 将再次添加。

关于javascript - 我的所有代码在由 Webpack 编译时都会运行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37081559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com