Skip to content

Commit f6bb414

Browse files
committed
feat($core): custom data block
1 parent b476ba4 commit f6bb414

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = () => ({
2+
name: '@vuepress/internal-data-block',
3+
4+
chainWebpack (config) {
5+
config
6+
.module
7+
.rule('data-block')
8+
.resourceQuery(/blockType=data/)
9+
.use('date-block-loader')
10+
.loader(require.resolve('./loader.js'))
11+
},
12+
13+
enhanceAppFiles () {
14+
return [{
15+
name: 'data-block',
16+
content: `
17+
export default ({ Vue }) => { Vue.mixin({
18+
computed: {
19+
$dataBlock() {
20+
return this.$options.__data__block__
21+
}
22+
}
23+
}) }`.trim()
24+
}]
25+
}
26+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function (source, map) {
2+
this.callback(
3+
null,
4+
`export default function (Component) {
5+
Component.options.__data__block__ = ${source.trim()}
6+
}`,
7+
map
8+
)
9+
}

packages/@vuepress/core/lib/prepare/AppContext.js

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module.exports = class AppContext {
115115
.use(require('../internal-plugins/layoutComponents'))
116116
.use(require('../internal-plugins/pageComponents'))
117117
.use(require('../internal-plugins/transformModule'))
118+
.use(require('../internal-plugins/dataBlock'))
118119
// user plugin
119120
.useByPluginsConfig(this.cliOptions.plugins)
120121
.useByPluginsConfig(this.siteConfig.plugins)

0 commit comments

Comments
 (0)