Vue3.x
的版本中build
后dist文件中出现legacy
的js
文件出现的主要原因可以参照
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>
是共存的
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">
.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小时内删除。
留言与评论(共有 0 条评论) |