微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webpack-5.x版本 启动server服务时的报错和解决办法

1.报错:

The 'mode' option has not been set, webpack will fallback to 'production' for this value.

原因:启动时,没有指定是开发模式还是线上模式

解决办法:

在启动时添加:--mode development   例如:"dev": "webpack server --mode development"

2.报错:

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).

WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.

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.

这3个问题都是一个原因:资源(asset)和入口起点超过指定文件限制,需要在 vue.config.js 文件内做如下配置

解决办法:

在webpack.config.js文件添加

  //警告 webpack 的性能提示
  performance: {
    hints:'warning',
    //入口起点的最大体积
    maxEntrypointSize: 50000000,
    //生成文件的最大体积
    maxAssetSize: 30000000,
    //只给出 js 文件性能提示
    assetFilter: function(assetFilename) {
      return assetFilename.endsWith('.js');
    }
  },

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐