When I build my js bundle with webpack using webpack-dev-server
my code runs twice every time. Not sure how to fix it.
Screenshot of Developer Tools console
My webpack config:
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') } ] } };
In webpack 4, the bundle-level minification is enabled automatically – both in the production mode and without one. It uses the UglifyJS minifier under the hood. (If you ever need to disable minification, just use the development mode or pass false to the optimization. minimize option.)
The file compression plug-in uglyfy-webpack-plugin on the official webpack page supports building with multiple CPU cores. This plug-in is supposed to be included in webpack by default in v1. 0.0, but now it needs to be manually installed via npm.
Code Splitting Code splitting is a feature provided by webpack to split your code into multiple bundles which can be used on-demand. Code splitting results in reduced bundle size which can help us in improving the load time, hence, improving the performance.
in the template file you might have manually added a loading the bundle.
If you don't have the
inject: false
option in
new HtmlWebpackPlugin({ template: path.join(__dirname, '../src/index.html') }),
the bundle will get added again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With