Skip to content

Commit d03dc3d

Browse files
authored
Merge pull request #11 from vue-styleguidist/feat-customlayout
feature: custom layout
2 parents 3f2446c + bed03a4 commit d03dc3d

File tree

8 files changed

+65
-9
lines changed

8 files changed

+65
-9
lines changed

chainWebpack.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
module.exports = function chainWebpack(config) {
2-
config.resolve.alias.set("vue$", "vue/dist/vue.esm.js");
1+
const path = require("path");
2+
3+
module.exports = options => {
4+
const layoutPath = options.layout || path.resolve(__dirname, "./layout.vue");
5+
return function(config) {
6+
config.resolve.alias
7+
.set("vue$", "vue/dist/vue.esm.js")
8+
.set("vuepress-plugin-live/live-layout", layoutPath);
9+
};
310
};

dangerfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const lockfileChanged = danger.git.modified_files.includes("package-lock.json");
88

99
if (packageChanged && !lockfileChanged) {
1010
warn(`Changes were made to \`package.json\`, but not to \`package-lock.json\`.
11-
If you’ve changed any dependencies (added, removed or updated any packages), please run \`yarn install\` and commit changes in package-lock.json file.`);
11+
If you’ve changed any dependencies (added, removed or updated any packages), please run \`npm install\` and commit changes in package-lock.json file. Make sure you’re using npm 5.7+.`);
1212
}
1313

1414
if (!packageChanged && lockfileChanged) {

docs/.vuepress/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ module.exports = {
1111
sidebar: ["/", "/Install.md"]
1212
},
1313
plugins: [
14-
[require("../../index")],
14+
[
15+
require("../../index"),
16+
{
17+
// uncomment this to use a custom layout
18+
// layout: path.resolve(__dirname, "../custom-layout")
19+
}
20+
],
1521
[
1622
"@vuepress/register-components",
1723
{

docs/Install.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ yarn add -D vuepress-plugin-live
1313

1414
In `.vuepress/config.js` add `["live"]` to the list of plugins
1515

16-
```js{3,4,5}
16+
```js{6,7,8,9,10,11,12}
17+
const path = require("path");
18+
1719
module.exports = {
1820
//...
1921
plugins: [
20-
["live"],
22+
[
23+
"live",
24+
{
25+
// optional: use layout to customize how the live editor is going to look like
26+
layout: path.resolve(__dirname, "./myCustomLayout.vue")
27+
}
28+
],
2129
[
2230
"@vuepress/register-components",
2331
{
@@ -32,3 +40,21 @@ module.exports = {
3240
]
3341
};
3442
```
43+
44+
### Options
45+
46+
#### `layout` (optional)
47+
48+
Absolute path to the layout vue-live is going to use.
49+
NOTA: the layout should have 2 slots named `preview` and `editor`.
50+
51+
Example layout (simplest):
52+
53+
```vue
54+
<template functional>
55+
<div>
56+
<slot name="preview"></slot>
57+
<slot name="editor"></slot>
58+
</div>
59+
</template>
60+
```

docs/custom-layout.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template functional>
2+
<div class="preview-code">
3+
<div class="preview block">
4+
<slot name="preview"></slot>
5+
</div>
6+
<div class="editor block">
7+
<slot name="editor"></slot>
8+
</div>
9+
</div>
10+
</template>
11+
12+
<style>
13+
.preview-code {
14+
border: 3px dashed green;
15+
}
16+
</style>

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const chainWebpack = require("./chainWebpack");
22
const enhanceAppFiles = require("./enhanceAppFiles");
33
const chainMarkdown = require("./markDownPlugin");
44

5-
module.exports = () => {
5+
module.exports = (options, app, plugin) => {
66
return {
77
name: "vuepress-plugin-live",
8-
chainWebpack,
8+
chainWebpack: chainWebpack(options),
99
enhanceAppFiles,
1010
chainMarkdown
1111
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Make your markdown code examples come alive ",
55
"main": "index.js",
66
"scripts": {
7+
"start": "npm run docs",
78
"docs": "vuepress dev docs --no-clear-screen",
89
"docs:build": "vuepress build docs"
910
},

vueLiveWithLayout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import layout from "./layout.vue";
1+
import layout from "vuepress-plugin-live/live-layout";
22

33
// vuepress is compiled in both node and non-node models
44
// it needs a "global" variable to make buble work.

0 commit comments

Comments
 (0)