Skip to content

Commit f514175

Browse files
authored
Merge pull request #1 from Atinux/nuxt-build-modules
chore: make it work for nuxt
2 parents 4489dcf + 719d92a commit f514175

File tree

8 files changed

+34
-44
lines changed

8 files changed

+34
-44
lines changed

example/nuxt.config.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
// Telemetry (https://github.com/nuxt/telemetry)
23
telemetry: false,
34

45
// Target (https://go.nuxtjs.dev/config-target)
@@ -15,23 +16,12 @@ export default {
1516
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
1617
},
1718

18-
// Global CSS (https://go.nuxtjs.dev/config-css)
19-
css: [],
20-
21-
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
22-
plugins: [],
23-
2419
// Auto import components (https://go.nuxtjs.dev/config-components)
2520
components: true,
2621

2722
// Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
2823
buildModules: [
2924
'vue-notion/nuxt'
30-
],
31-
32-
// Modules (https://go.nuxtjs.dev/config-modules)
33-
modules: [],
25+
]
3426

35-
// Build Configuration (https://go.nuxtjs.dev/config-build)
36-
build: {},
3727
};

example/pages/_slug.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88
</template>
99

1010
<script>
11-
import { NotionRenderer, getPageBlocks, getPageTable } from "vue-notion";
12-
1311
import "prismjs";
1412
import "prismjs/themes/prism.css";
1513
1614
export default {
17-
components: { NotionRenderer },
1815
data() {
1916
return {
2017
pageLinkOptions: { component: "NuxtLink", href: "to" },
2118
};
2219
},
23-
async asyncData({ params, error }) {
24-
const pageTable = await getPageTable("10327f9074b7433aad577ccd0020e971");
20+
async asyncData({ $notion, params, error }) {
21+
const pageTable = await $notion.getPageTable("10327f9074b7433aad577ccd0020e971");
2522
const page = pageTable.find(
2623
(item) => item.published && item.slug === params.slug
2724
);
28-
const blockMap = await getPageBlocks(page ? page.id : params.slug);
25+
const blockMap = await $notion.getPageBlocks(page ? page.id : params.slug);
2926
if (!blockMap || blockMap.error) {
3027
return error({ statusCode: 404, message: "Post not found" });
3128
}

example/pages/basic-example.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
</template>
44

55
<script>
6-
import { NotionRenderer, getPageBlocks } from "vue-notion";
7-
86
export default {
9-
components: { NotionRenderer },
107
data: () => ({ blockMap: null }),
11-
async created() {
8+
async asyncData({ $notion }) {
129
// get Notion blocks from the API via a Notion pageId
13-
this.blockMap = await getPageBlocks("8c1ab01960b049f6a282dda64a94afc7");
10+
const blockMap = await $notion.getPageBlocks("8c1ab01960b049f6a282dda64a94afc7");
11+
12+
return { blockMap }
1413
},
1514
};
1615
</script>

example/pages/posts.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
</template>
3636

3737
<script>
38-
import { getPageTable } from "vue-notion";
39-
4038
export default {
41-
async asyncData({ params, error }) {
42-
const pageTable = await getPageTable("10327f9074b7433aad577ccd0020e971");
39+
async asyncData({ $notion, params, error }) {
40+
const pageTable = await $notion.getPageTable("10327f9074b7433aad577ccd0020e971");
4341
4442
// sort published pages
4543
const posts = pageTable

nuxt/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
21
import path from 'path'
3-
// import defu from 'defu'
2+
import defu from 'defu'
3+
4+
const defaultOptions = {}
45

56
module.exports = function (moduleOptions) {
6-
// const options = defu({
7-
// ...this.options.notion,
8-
// ...moduleOptions
9-
// }, defaultOptions)
7+
const options = defu({
8+
...this.options.notion,
9+
...moduleOptions
10+
}, defaultOptions)
1011

1112
this.nuxt.hook('build:before', () => {
1213
console.log('this.options.build => ', this.options.build)
1314

1415
// Enable transpilation of `src/` directory
15-
this.options.build.transpile.push('vue-notion/src')
16+
this.options.build.transpile.push('vue-notion')
1617

1718
console.log('this.options.build after => ', this.options.build)
1819

1920
this.addPlugin({
2021
src: path.resolve(__dirname, 'plugin.js'),
21-
mode: 'client',
22-
ssr: false,
23-
fileName: 'vue-notion.client.js',
24-
// options
22+
fileName: 'vue-notion.js'
2523
})
2624
})
2725
}

nuxt/plugin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import Notion from 'vue-notion'
1+
import Vue from 'vue'
2+
import VueNotion from 'vue-notion'
3+
import { getPageBlocks, getPageTable } from 'vue-notion'
24

3-
const NotionPlugin = (context, inject) => {
4-
const notion = Notion
5-
inject('notion', notion)
6-
}
5+
Vue.use(VueNotion)
76

8-
export default NotionPlugin
7+
export default (_, inject) => {
8+
const notion = { getPageBlocks, getPageTable }
9+
inject('notion', notion)
10+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"dependencies": {
2828
"cross-fetch": "^3.0.6",
29+
"defu": "^3.2.2",
2930
"vue-fragment": "^1.5.1",
3031
"vue-prism-component": "^1.2.0"
3132
},

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,11 @@ define-property@^2.0.2:
32313231
is-descriptor "^1.0.2"
32323232
isobject "^3.0.1"
32333233

3234+
defu@^3.2.2:
3235+
version "3.2.2"
3236+
resolved "https://registry.yarnpkg.com/defu/-/defu-3.2.2.tgz#be20f4cc49b9805d54ee6b610658d53894942e97"
3237+
integrity sha512-8UWj5lNv7HD+kB0e9w77Z7TdQlbUYDVWqITLHNqFIn6khrNHv5WQo38Dcm1f6HeNyZf0U7UbPf6WeZDSdCzGDQ==
3238+
32343239
del@^4.1.1:
32353240
version "4.1.1"
32363241
resolved "https://registry.yarnpkg.com/del/-/del-4.1.1.tgz#9e8f117222ea44a31ff3a156c049b99052a9f0b4"

0 commit comments

Comments
 (0)