webpack 热更新时 warnings

错误

WARNING in configuration
The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
  print.0989fjs (348 KiB)
  vendors.0989fjs (357 KiB)
  index.0989fjs (885 KiB)

WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  index (885 KiB)
      index.0989fjs
  vendors (357 KiB)
      vendors.0989fjs
  print (348 KiB)
      print.0989fjs


WARNING in webpack performance recommendations:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/

这是配置文件

const webpack = require('webpack');

module.exports = {
    // devtool: 'inline-source-map',
    devServer: {
        contentBase: './dist',
        compress:true,
        port:9000,
        host:'127.0.0.1',
        hot: true, 
       
    },
    entry: {
        index: './src/index.js',
        vendors: ['react'],
        
    },

    plugins: [
        new CleanWebpackPlugin(['dist']),
        new HTMLWebpackPlugin({
            title: 'Code Splitting'
        }),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()

    
    ],
    
    output: {
        filename: '[name].[hash:5]js',
        path: path.resolve(__dirname, 'dist'),
        hotUpdateChunkFilename: 'hot/hot-update.js',  //指定热替换补丁js文件和
        hotUpdateMainFilename: 'hot/hot-update.json', //json描述文件生成路径 ,每次文件变化都会生成一次
    }
};

要如何处理呢

阅读 8k
2 个回答

你这是webpack4的配置吧 webpack4的配置现在要加多一个mode来判断是开发环境还是生产环境
`const webpack = require('webpack');

module.exports = {

// devtool: 'inline-source-map',
    mode: "development", //加上这一句试试
devServer: {
    contentBase: './dist',
    compress:true,
    port:9000,
    host:'127.0.0.1',
    hot: true, 
   
},
entry: {
    index: './src/index.js',
    vendors: ['react'],
    
},

plugins: [
    new CleanWebpackPlugin(['dist']),
    new HTMLWebpackPlugin({
        title: 'Code Splitting'
    }),
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin()


],

output: {
    filename: '[name].[hash:5]js',
    path: path.resolve(__dirname, 'dist'),
    hotUpdateChunkFilename: 'hot/hot-update.js',  //指定热替换补丁js文件和
    hotUpdateMainFilename: 'hot/hot-update.json', //json描述文件生成路径 ,每次文件变化都会生成一次
}

};`

嗯嗯 好用了 但是为啥我的页面并没有更新呢

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题