@@ -5,26 +5,32 @@ const { EventEmitter } = require('events')
5
5
const { getOptions } = require ( 'loader-utils' )
6
6
const { inferTitle, extractHeaders, parseFrontmatter } = require ( '../util' )
7
7
const LRU = require ( 'lru-cache' )
8
+ const { mdExplodeIncludes } = require ( './util' )
8
9
9
10
const cache = LRU ( { max : 1000 } )
10
11
const devCache = LRU ( { max : 1000 } )
11
12
12
13
module . exports = function ( src ) {
14
+ const file = this . resourcePath
15
+ const cwd = path . dirname ( file )
16
+
17
+ const { explodedSrc, dependencies } = mdExplodeIncludes ( { cwd, src } )
18
+ dependencies . forEach ( d => this . addDependency ( d ) )
19
+
13
20
const isProd = process . env . NODE_ENV === 'production'
14
21
const isServer = this . target === 'node'
15
22
const { markdown, sourceDir } = getOptions ( this )
16
23
17
24
// we implement a manual cache here because this loader is chained before
18
25
// vue-loader, and will be applied on the same file multiple times when
19
26
// selecting the individual blocks.
20
- const file = this . resourcePath
21
- const key = hash ( file + src )
27
+ const key = hash ( file + explodedSrc )
22
28
const cached = cache . get ( key )
23
29
if ( cached && ( isProd || / \? v u e / . test ( this . resourceQuery ) ) ) {
24
30
return cached
25
31
}
26
32
27
- const frontmatter = parseFrontmatter ( src )
33
+ const frontmatter = parseFrontmatter ( explodedSrc )
28
34
const content = frontmatter . content
29
35
30
36
if ( ! isProd && ! isServer ) {
@@ -66,9 +72,8 @@ module.exports = function (src) {
66
72
const altname = shortname
67
73
. replace ( / \/ $ / , '/index.md' )
68
74
. replace ( / ^ \/ / , sourceDir + '/' )
69
- const dir = path . dirname ( this . resourcePath )
70
- const file = path . resolve ( dir , filename )
71
- const altfile = altname !== filename ? path . resolve ( dir , altname ) : null
75
+ const file = path . resolve ( cwd , filename )
76
+ const altfile = altname !== filename ? path . resolve ( cwd , altname ) : null
72
77
if ( ! fs . existsSync ( file ) && ( altfile && ! fs . existsSync ( altfile ) ) ) {
73
78
this . emitWarning (
74
79
new Error (
0 commit comments