手册目录
入门
资源
转换
代码拆分
生产环境
配置
生产环境
当需要打包应用程序用于生产环境时,可以使用 Parcel 的生产模式。
parcel build entry.js
这将禁用 监听(watch) 模式和模块热更换,所以它只会构建一次。它还会开启 minifier 用于压缩输出包文件的大小。Parcel使用的 minifiers 包括用于 JavaScript 的 uglify-es,用于 CSS 的 cssnano,和用于 HTML 的 htmlnano。
启用生产模式还需要设置 NODE_ENV = production 环境变量。 像 React 这样的大型库有开发调试功能,通过设置这个环境变量来禁用调试功能,从而使生产的构建更小更快。
选项
设置输出目录
默认: "dist"
parcel build entry.js --out-dir build/output 或者 parcel build entry.js -d build/output
root - build - - output - - - entry.js
设置要提供服务的公共 URL
默认: --out-dir option
parcel build entry.js --public-url ./
将输出:
<link rel="stylesheet" type="text/css" href="1a2b3c4d.css"> or <script src="e5f6g7h8.js"></script>
禁用压缩
默认: minification enabled
parcel build entry.js --no-minify
禁用文件系统缓存
默认: cache enabled
parcel build entry.js --no-cache
相关视频
科技资讯
24小时阅读榜
1
2
3
4
5
6
7
8
9
10
精品课程
共5课时 | 17.4万人学习
共49课时 | 78.2万人学习
共29课时 | 62.5万人学习
共25课时 | 39.8万人学习
共43课时 | 73.8万人学习