Node.js/nuxt/其他:修订间差异
来自康健生活
| 第38行: | 第38行: | ||
const buffer= fs.readFileSync('./assets/fonts/icon/iconfont.js') | const buffer= fs.readFileSync('./assets/fonts/icon/iconfont.js') | ||
module.exports = `${String(buffer)}`</syntaxhighlight>}} | module.exports = `${String(buffer)}`</syntaxhighlight>}} | ||
=== 添加 css 文件 === | |||
有个新需求是也许还会添加 css 文件 | |||
{{hc|nuxt.config.js|<syntaxhighlight lang="javascript"> | |||
// html head 中创建 script 标签 | |||
script: [ | |||
{innerHTML: require('./plugins/icon.ts').iconJs(), type: 'text/javascript', charset: 'utf-8'} | |||
], | |||
// 不对<script>标签中内容做转义处理 | |||
__dangerouslyDisableSanitizers: ['script','style'], | |||
link: [ | |||
{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}, | |||
], | |||
style: [ | |||
{rel: 'iconfont', type: 'text/css', innerHTML: require('./plugins/icon.ts').iconCss()}, | |||
],</syntaxhighlight>}} | |||
同时我把 icon.ts 文件更新了一下 | |||
<syntaxhighlight lang="javascript"> | |||
/** | |||
* @author kangkk | |||
* @description 引用 iconfont 里面的 js 文件,直接引用会报出 window 未定义 | |||
* @type {module:fs} | |||
*/ | |||
const fs = require("fs") | |||
// module.exports = `${String(buffer)}` | |||
export function iconJs () { | |||
const buffer = fs.readFileSync('./assets/fonts/icon/iconfont.js') | |||
return `${String(buffer)}` | |||
} | |||
export function iconCss () { | |||
const buffer = fs.readFileSync('./assets/fonts/icon/iconfont.css') | |||
return `${String(buffer)}` | |||
}</syntaxhighlight> | |||