Skip to content

Commit 990792b

Browse files
authored
Supported Nuxt3 (#5)
* Nuxt3対応 * targetの値のclientをallに変更 * fix .ts * fix import type * update packages * add attention
1 parent 56222d5 commit 990792b

File tree

20 files changed

+6281
-3438
lines changed

20 files changed

+6281
-3438
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 2
5+
indent_style = space
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.eslintrc

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
{
22
"root": true,
3-
"env": {
4-
"browser": true,
5-
"es6": true,
6-
"node": true
7-
},
8-
"extends": [
9-
"@nuxtjs/eslint-config-typescript"
10-
],
11-
"parser": "@typescript-eslint/parser",
12-
"parserOptions": {
13-
"sourceType": "module"
14-
},
15-
"rules": {
16-
"semi": ["error", "always"],
17-
"quotes": ["error", "single", { "allowTemplateLiterals": true }]
18-
}
19-
}
3+
"extends": ["@nuxt/eslint-config", "prettier"]
4+
}

.github/workflows/release.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v1
14-
with:
15-
node-version: '14.x'
16-
registry-url: 'https://registry.npmjs.org'
17-
- name: release on npm
18-
run: |
19-
npm ci
20-
npm run lint
21-
npm run build
22-
- run: npm publish
23-
env:
24-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: '16.x'
16+
registry-url: 'https://registry.npmjs.org'
17+
cache: 'yarn'
18+
- run: yarn install --frozen-lockfile
19+
- name: release on npm
20+
run: yarn release
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 46 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,56 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
1+
# Dependencies
2+
node_modules
523

53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
4+
# Logs
5+
*.log*
746

75-
# parcel-bundler cache (https://parceljs.org/)
7+
# Temp directories
8+
.temp
9+
.tmp
7610
.cache
7711

78-
# Next.js build output
79-
.next
12+
# Yarn
13+
**/.yarn/cache
14+
**/.yarn/*state*
8015

81-
# Nuxt.js build / generate output
82-
.nuxt
16+
# Generated dirs
8317
dist
8418

85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
19+
# Nuxt
20+
.nuxt
21+
.output
22+
.vercel_build_output
23+
.build-*
24+
.env
25+
.netlify
9626

97-
# FuseBox cache
98-
.fusebox/
27+
# Env
28+
.env
9929

100-
# DynamoDB Local files
101-
.dynamodb/
30+
# Testing
31+
reports
32+
coverage
33+
*.lcov
34+
.nyc_output
10235

103-
# TernJS port file
104-
.tern-port
36+
# VSCode
37+
.vscode/*
38+
!.vscode/settings.json
39+
!.vscode/tasks.json
40+
!.vscode/launch.json
41+
!.vscode/extensions.json
42+
!.vscode/*.code-snippets
43+
44+
# Intellij idea
45+
*.iml
46+
.idea
47+
48+
# OSX
49+
.DS_Store
50+
.AppleDouble
51+
.LSOverride
52+
.AppleDB
53+
.AppleDesktop
54+
Network Trash Folder
55+
Temporary Items
56+
.apdisk

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shamefully-hoist=true
2+
strict-peer-dependencies=false

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

README.md

Lines changed: 95 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
⚠️ Nuxt3 is not supported. Please use Nuxt2.
2-
31
# nuxt-microcms-module
4-
[microCMS](https://microcms.io) integration for [Nuxt](https://nuxtjs.org/).
2+
3+
[microCMS](https://microcms.io) integration for [Nuxt](https://nuxt.com/).
4+
5+
Attention❗️
6+
This module is intended for Nuxt version 3. If you are using version 2, please perform `npm install nuxt-microcms-module@2` and refer [here](https://github.com/microcmsio/nuxt-microcms-module/tree/v2#readme).
57

68
## Getting Started
79

@@ -13,63 +15,116 @@ $ npm install nuxt-microcms-module
1315

1416
### Setup
1517

16-
```javascript
17-
// nuxt.config.js
18-
19-
export default {
18+
```typescript
19+
// nuxt.config.ts
20+
21+
export default defineNuxtConfig({
22+
modules: [
23+
[
24+
'nuxt-microcms-module',
25+
{
26+
serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
27+
apiKey: 'YOUR_API_KEY',
28+
// target: 'server',
29+
},
30+
],
31+
],
32+
// or
2033
modules: ['nuxt-microcms-module'],
21-
microcms: {
22-
options: {
23-
serviceDomain: "YOUR_DOMAIN", // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
24-
apiKey: "YOUR_API_KEY",
25-
},
26-
mode: process.env.NODE_ENV === 'production' ? 'server' : 'all',
34+
microCMS: {
35+
serviceDomain: 'YOUR_DOMAIN',
36+
apiKey: 'YOUR_API_KEY',
37+
// target: 'server',
2738
},
28-
};
39+
});
2940
```
3041

31-
#### options.serviceDomain
42+
#### serviceDomain
43+
3244
`String`
45+
Required.
3346
Your service id, which is a subdomain of microCMS.
3447

35-
#### options.apiKey
48+
#### apiKey
49+
3650
`String`
51+
Required.
3752
Your api-key.
38-
It can be obtained from the service settings.
53+
It can be obtained from the service settings.
54+
55+
#### target
3956

40-
#### mode
41-
`String` (can be `client` or `server` or `all`)
42-
If defined, this module will be included only on the respective (client or server) side.
57+
`String` (can be `server` or `all`)
58+
Default: `server`
59+
By setting this value to `all`, the api-key you set will be included in the client-side code.
60+
This will allow the client side to send requests to microCMS.
61+
If you only want to send requests to microCMS at build time or from the server side, set this value to `server` or leave it blank.
4362

4463
### Hot to use
45-
This package uses [microcms-js-sdk](https://github.com/microcmsio/microcms-js-sdk).
46-
You can get microCMS client (`$microcms`) from `context`.
47-
Please see the URL below for details.
48-
https://github.com/microcmsio/microcms-js-sdk#how-to-use
4964

50-
```vue
51-
// pages/index.vue
65+
We provide several custom hooks that can be used globally.
66+
These are functions that internally wrap useFetch.
5267

68+
```typescript
69+
type useMicroCMSGetList = <T>(
70+
args: {
71+
endpoint: string;
72+
queries?: MicroCMSQueries;
73+
},
74+
fetchOptions?: FetchOptions
75+
) => Promise<AsyncData<MicroCMSListResponse<T>>>;
76+
type useMicroCMSGetListDetail = <T>(
77+
args: {
78+
endpoint: string;
79+
contentId: string;
80+
queries?: MicroCMSQueries;
81+
},
82+
fetchOptions?: FetchOptions
83+
) => Promise<AsyncData<T & MicroCMSListContent>>;
84+
type useMicroCMSGetObject = <T>(
85+
args: {
86+
endpoint: string;
87+
queries?: MicroCMSQueries;
88+
},
89+
fetchOptions?: FetchOptions
90+
) => Promise<AsyncData<T & MicroCMSObjectContent>>;
91+
92+
// FetchOptions is the same as the second argument option of useFetch provided by Nuxt3.
93+
// AsyncData is the return value of useFetch.
94+
// https://nuxt.com/docs/api/composables/use-fetch
95+
```
96+
97+
```vue
5398
<template>
5499
<ul>
55-
<li v-for="content in contents" :key="content.id">
56-
<nuxt-link :to="`/${content.id}`">
57-
{{ content.title }}
58-
</nuxt-link>
100+
<li v-for="blog in blogs?.contents" :key="blog.id">
101+
<NuxtLink :to="`/${blog.id}`">
102+
<img
103+
:src="blog.eyecatch.url"
104+
:width="blog.eyecatch.width"
105+
:height="blog.eyecatch.height"
106+
alt=""
107+
/>
108+
<span>
109+
{{ blog.title }}
110+
</span>
111+
</NuxtLink>
59112
</li>
60113
</ul>
61114
</template>
62115
63-
<script>
64-
export default {
65-
async asyncData({ $microcms }) {
66-
const data = await $microcms.get({
67-
endpoint: 'your_endpoint',
68-
queries: { limit: 20, filters: 'createdAt[greater_than]2021' },
69-
});
70-
return data;
71-
}
72-
}
116+
<script setup lang="ts">
117+
import type { MicroCMSImage } from 'microcms-js-sdk';
118+
119+
type Blog = {
120+
title: string;
121+
eyecatch: MicroCMSImage;
122+
};
123+
124+
const { data: blogs } = await useMicroCMSGetList<Blog>({
125+
endpoint: 'blogs',
126+
queries: { fields: ['id', 'title', 'eyecatch'] },
127+
});
73128
</script>
74129
```
75130

0 commit comments

Comments
 (0)