@rollup/plugin-html 参数

@rollup/plugin-html插件用于生成HTML并注入JS,支持自定义标题、资源路径、模板和文件名。通过调整参数如publicPath和template,能更好地定制HTML输出。

`@rollup/plugin-html` 是一个用于生成 HTML 文件的插件。通过 `@rollup/plugin-html`,您可以将 Rollup 中打包的 JavaScript 文件自动注入到 HTML 中,并可以自定义输出的 HTML 模板,添加自己的元数据等。以下是 `@rollup/plugin-html` 可用的参数:

#### `title`

- 类型: `string`

- 默认值: `'Rollup'`

用于指定生成的 HTML 文件的标题。

#### `publicPath`

- 类型: `string`

- 默认值: `'/'`

用于指定资源文件的引用路径。例如,如果资源文件位于 `public/assets` 目录中,则可以将 `publicPath` 设置为 `/assets/`,从而在 HTML 文件中的资源文件引用路径中添加前缀 `/assets/`。

#### `template`

- 类型: `string`

- 默认值: `'<!doctype html>'`

用于指定 HTML 模板文件的路径。如果您指定了 HTML 模板文件,则 `@rollup/plugin-html` 会将打包生成的 JavaScript 文件插入到该模板文件中,生成最终的 HTML 文件。如果您未指定 HTML 模板文件,则默认生成一个简单的 HTML 文件。

#### `fileName`

- 类型: `string`

- 默认值: `'index.html'`

指定生成的 HTML 文件的文件名。

#### `context`

- 类型: `object`

- 默认值: `{}`

您可以在该参数中设置上下文对象,然后在 HTML 模板文件中通过变量名来访问该上下文对象,从而对 HTML 文件进行更多的自定义设置。

以上是 `@rollup/plugin-html` 可用的参数。您可以根据您的需求来自定义这些参数来生成您需要的 HTML 文件。

import path from 'path'; import * as fs from 'fs'; import * as https from 'https'; import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import eslint from 'vite-plugin-eslint'; import { visualizer } from 'rollup-plugin-visualizer'; import * as ssl from 'ssl-root-cas'; import { commonAssetsPrefix } from './src/constants/config-env'; const { ANALYZE } = process.env; const rootCas = ssl.create(); rootCas.addFile(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/cert.pem')); https.globalAgent.options.ca = rootCas; function getHttpsConfig() { return { cert: fs.readFileSync(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/cert.pem')), key: fs.readFileSync(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/key.pem')), }; } export default defineConfig(config => ({ base: config.mode === 'production' ? commonAssetsPrefix : '/', resolve: { alias: { '@': path.resolve(__dirname, 'src'), '@aurora/theme': '@aurora/theme-saas', }, }, css: { preprocessorOptions: { scss: { additionalData: '@import "./theme-saas/styles.scss";', }, }, }, plugins: [ vue(), eslint({ // 检查出“警告”级别的问题时,输出警告到控制台 emitWarning: true, // 检查出“错误”级别的问题时,不输出为 error(不抛出 error,不影响渲染,只输出 错误信息) emitError: false, // 检查出 warning 时,不让打包/启动失败 failOnWarning: false, }), ...(ANALYZE === 'true' ? [ visualizer({ open: false, gzipSize: true, brotliSize: true, filename: 'dist/stats.html', }), ] : []), ], build: { target: 'esnext', }, define: { VERSION_PLACEHOLDER: JSON.stringify('1.0.0'), __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, 'process.env': Object.assign({}, process.env), }, server: { hmr: true, port: 4173, open: true, host: 'localhost.huawei.com', cors: true, proxy: { '/ffe': { target: 'https://kwesit.huawei.com', changeOrigin: true, rewrite: pathItem => pathItem.replace(/^\/ffe/, ''), }, }, https: getHttpsConfig(), }, })); 以上是我的vite设置,打包后部署完打开index。html白屏,无任何报错,帮忙看看可能是什么原因
08-01
import path from 'path'; import * as fs from 'fs'; import * as https from 'https'; import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import eslint from 'vite-plugin-eslint'; import { visualizer } from 'rollup-plugin-visualizer'; import * as ssl from 'ssl-root-cas'; import { commonAssetsPrefix } from './src/constants/config-env'; const { ANALYZE } = process.env; const rootCas = ssl.create(); rootCas.addFile(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/cert.pem')); https.globalAgent.options.ca = rootCas; function getHttpsConfig() { return { cert: fs.readFileSync(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/cert.pem')), key: fs.readFileSync(path.resolve(__dirname, 'node_modules/@ffe/fcore-build-utils/.certs/key.pem')), }; } export default defineConfig(config => ({ base: config.mode === 'production' ? commonAssetsPrefix : '/', resolve: { alias: { '@': path.resolve(__dirname, 'src'), '@aurora/theme': '@aurora/theme-saas', }, }, css: { preprocessorOptions: { scss: { additionalData: '@import "./theme-saas/styles.scss";', }, }, }, plugins: [ vue(), eslint({ // 检查出“警告”级别的问题时,输出警告到控制台 emitWarning: true, // 检查出“错误”级别的问题时,不输出为 error(不抛出 error,不影响渲染,只输出 错误信息) emitError: false, // 检查出 warning 时,不让打包/启动失败 failOnWarning: false, }), ...(ANALYZE === 'true' ? [ visualizer({ open: false, gzipSize: true, brotliSize: true, filename: 'dist/stats.html', }), ] : []), ], build: { target: 'esnext', }, define: { VERSION_PLACEHOLDER: JSON.stringify('1.0.0'), __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, 'process.env': Object.assign({}, process.env), }, server: { hmr: true, port: 4173, open: false, host: 'localhost.huawei.com', cors: true, proxy: { '/ffe': { target: 'https://kwesit.huawei.com', changeOrigin: true, rewrite: pathItem => pathItem.replace(/^\/ffe/, ''), }, }, https: getHttpsConfig(), }, })); 以上是我的vite配置,如何调整能使其在测试环境 打包的代码不混淆压缩,使得测试环境能读懂代码
最新发布
08-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值