Vue3.x的版本中build后dist文件中出现legacy的js文件

阅读: 评论:0

Vue3.x的版本中build后dist文件中出现legacy的js文件

Vue3.x的版本中build后dist文件中出现legacy的js文件

Vue3.x的版本中build后dist文件中出现legacyjs文件

1. 问题描述

出现的主要原因可以参照
vue脚手架文档的解释(这里是英文文档, 主要是目前老夫写这个博客时, 中文文档没有这个页面)
vue现代模式说明

老夫的理解其实就是官方目前为了开启<script type="module">的现代模式, 又为了适配低版本的浏览器从而添加<script nomodule>, 其实最直观的感受就是打包的速度变慢了

🚨🚨🚨 老夫使用的是yarn各位彦祖可以直接替换为npm的, dist/js中带有.gz后缀的是为了配置nginx的, 可以直接无视无视🚨🚨🚨

问题是如果直接使用yarn build目前是默认开启了现代模式, 就相当于是输入了yarn build --modern vue脚手架中对于build配置的部分说明

这是dist/js中的打包后的代码🚀

这是打包后的 dist/index.html的文件, 之所以这样子,是因为被我格式化了🙈, 可以看到, <script type="module"><script nomodule>是共存的

2. 解决方法-不需要 type=“module”

2.1 可以yarn build --no-module

yarn build --no-module说明打包之后,不生成<script type="module">

npx vue-cli-service help build可以查看 build 后面添加的指令

Usage: vue-cli-service build [options] [entry|pattern]Options:--mode         specify env mode (default: production)--dest         specify output directory (default: dist)--no-module    build app without generating <script type="module"> chunks for modern browsers--target       app | lib | wc | wc-async (default: app)--inline-vue   include the Vue module in the final bundle of library or web component target--formats      list of output formats for library builds (default: commonjs,umd,umd-min)--name         name for lib or web-component mode (default: "name" in package.json or entry filename)--filename     file name for output, only usable for 'lib' target (default: value of --name)--no-clean     do not remove the dist directory contents before building the project  --report       generate report.html to help analyze bundle content--report-json  generate report.json to help analyze bundle content--skip-plugins comma-separated list of plugin names to skip for this run--watch        watch for changes--stdin        close when stdin ends

打包后的dist/js中的文件

这是打包后的 dist/index.html的文件, 是没有了<script type="module">

2.2 可以在.browserslistrc文件或者package.json中添加

browserslist的文档说明
.browserslistrc文件

> 1%
last 2 versions
not dead
not IE 11

package.json

"dependencies" : {},
"devDependencies": {},
"browserslist": ["> 1%","last 2 versions","not dead","not ie 11"
]

两者选一个即可, 最后直接yarn build就行

本文发布于:2024-02-01 10:07:44,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170675326635883.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:文件   版本   build   js   legacy
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23