-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmodule.ts
55 lines (46 loc) · 1.2 KB
/
module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { resolve, join } from 'path'
import defu from 'defu'
import { ModuleOptions, ModuleLoader, moduleDefaults } from './options'
import './types'
// https://github.com/BlueOakJS/markdownit-loader
// https://github.com/markdown-it/markdown-it
function markdownitModule (moduleOptions) {
const { nuxt, extendBuild, addPlugin } = this
// Merge all option sources
const options: ModuleOptions = defu(
moduleOptions,
nuxt.options.markdownit,
moduleDefaults
)
// Define module loader for markdownit
const moduleLoader: ModuleLoader = {
loader: '@nuxtjs/markdownit-loader',
options
}
// Extend webpack configuration
extendBuild((config) => {
config.module.rules.push({
test: /\.md$/,
oneOf: [
{
resourceQuery: /^\?vue/,
use: [moduleLoader]
},
{
use: ['raw-loader', moduleLoader]
}
]
})
})
if (options.runtime === true) {
delete options.runtime
// Register plugin
addPlugin({
src: resolve(__dirname, 'runtime/plugin.js'),
fileName: join('markdownit.js'),
options
})
}
}
markdownitModule.meta = require('../package.json')
export default markdownitModule