DOCX loader for unplugin
English | 简体中文
use mammoth
convert docx to html
Motivation
In developing software, it is often necessary to add some privacy and user agreement contents to the page, and the legal affairs are often provided as word documents. This time we need to convert it to html
first, and then write it into the template. So the plugin is written to automatically do the conversion process.
(PS: more suitable for plain text word)
Install
npm i unplugin-docx
Vite
// vite.config.ts
import Docx from 'unplugin-docx/vite'
export default defineConfig({
plugins: [
Docx({ /* options */ }),
],
})
Example: playground/
Rollup
// rollup.config.js
import Docx from 'unplugin-docx/rollup'
export default {
plugins: [
Docx({ /* options */ }),
],
}
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-docx/webpack')({ /* options */ })
]
}
Nuxt
// nuxt.config.js
export default {
buildModules: [
['unplugin-docx/nuxt', { /* options */ }],
],
}
This module works for both Nuxt 2 and Nuxt Vite
Vue CLI
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-docx/webpack')({ /* options */ }),
],
},
}
Configuration
Pefer to the mammoth.convertToHtml's options for detail.
Usage
we can import docx
as plain HTML
import html from './demo.docx'
document.getElementById('app')!.innerHTML = html
⚠️ if you use
TypeScript
, you should declear*.docx
module like below
declare module '*.docx' {
const content: string
export default content
}