# How to get rid of markdown-it for optimizing the bundle size of the Vue2 app.
The size of markdown-it is slightly big. If your app is slow to start due to bundle download time, you can remove it from the bundle by using markdown-it with the CDN.
# Add the CDN link to index.html
Add the CDN link to the file index.html
under the public
folder.
For example:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- markdown-it -->
<script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.js"></script>
</head>
# Add external setting
Add an external setting of xterm on the vue.config.js
file as refer markdown-it
for the external global variable named without a hyphen as markdown
as follows:
module.exports = {
chainWebpack: (config) => {
config.externals({
"markdown-it":"markdownit",
})
}
}
# import markdown-it as usual
In the .vue file using the markdown-it, import markdown-it
as usual.
Fx:
<template>
<div>
<div v-html="md.render(news)"/>
</div>
</template>
<script>
var MarkdownIt = require('markdown-it')
export default {
data: () => ({
md: new MarkdownIt({
}),
news: "# still in development"
}),
}
</script>
# references
- MarkdownIt (opens new window): usage document of main parser/renderer class of markdown-it. The example of "browser without AMD" is informative.