Skip to content

Commit bed1450

Browse files
committed
initial commit
1 parent e4980c2 commit bed1450

21 files changed

+6981
-0
lines changed

.editorconfig

+12
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.eslintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": ["@nuxt/eslint-config"]
4+
}

.gitignore

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Logs
5+
*.log*
6+
7+
# Temp directories
8+
.temp
9+
.tmp
10+
.cache
11+
12+
# Yarn
13+
**/.yarn/cache
14+
**/.yarn/*state*
15+
16+
# Generated dirs
17+
dist
18+
19+
# Nuxt
20+
.nuxt
21+
.output
22+
.data
23+
.vercel_build_output
24+
.build-*
25+
.netlify
26+
27+
# Env
28+
.env
29+
30+
# Testing
31+
reports
32+
coverage
33+
*.lcov
34+
.nyc_output
35+
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shamefully-hoist=true
2+
strict-peer-dependencies=false

.nuxtrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports.autoImport=false
2+
typescript.includeWorkspace=true

README.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!--
2+
Get your module up and running quickly.
3+
4+
Find and replace all on all files (CMD+SHIFT+F):
5+
- Name: My Module
6+
- Package name: my-module
7+
- Description: My new Nuxt module
8+
-->
9+
10+
# My Module
11+
12+
[![npm version][npm-version-src]][npm-version-href]
13+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
14+
[![License][license-src]][license-href]
15+
[![Nuxt][nuxt-src]][nuxt-href]
16+
17+
My new Nuxt module for doing amazing things.
18+
19+
- [&nbsp;Release Notes](/CHANGELOG.md)
20+
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
21+
<!-- - [📖 &nbsp;Documentation](https://example.com) -->
22+
23+
## Features
24+
25+
<!-- Highlight some of the features your module provide here -->
26+
-&nbsp;Foo
27+
- 🚠 &nbsp;Bar
28+
- 🌲 &nbsp;Baz
29+
30+
## Quick Setup
31+
32+
1. Add `my-module` dependency to your project
33+
34+
```bash
35+
# Using pnpm
36+
pnpm add -D my-module
37+
38+
# Using yarn
39+
yarn add --dev my-module
40+
41+
# Using npm
42+
npm install --save-dev my-module
43+
```
44+
45+
2. Add `my-module` to the `modules` section of `nuxt.config.ts`
46+
47+
```js
48+
export default defineNuxtConfig({
49+
modules: [
50+
'my-module'
51+
]
52+
})
53+
```
54+
55+
That's it! You can now use My Module in your Nuxt app ✨
56+
57+
## Development
58+
59+
```bash
60+
# Install dependencies
61+
npm install
62+
63+
# Generate type stubs
64+
npm run dev:prepare
65+
66+
# Develop with the playground
67+
npm run dev
68+
69+
# Build the playground
70+
npm run dev:build
71+
72+
# Run ESLint
73+
npm run lint
74+
75+
# Run Vitest
76+
npm run test
77+
npm run test:watch
78+
79+
# Release new version
80+
npm run release
81+
```
82+
83+
<!-- Badges -->
84+
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
85+
[npm-version-href]: https://npmjs.com/package/my-module
86+
87+
[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
88+
[npm-downloads-href]: https://npmjs.com/package/my-module
89+
90+
[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
91+
[license-href]: https://npmjs.com/package/my-module
92+
93+
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
94+
[nuxt-href]: https://nuxt.com

package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "my-module",
3+
"version": "1.0.0",
4+
"description": "My new Nuxt module",
5+
"repository": "your-org/my-module",
6+
"license": "MIT",
7+
"type": "module",
8+
"exports": {
9+
".": {
10+
"types": "./dist/types.d.ts",
11+
"import": "./dist/module.mjs",
12+
"require": "./dist/module.cjs"
13+
}
14+
},
15+
"main": "./dist/module.cjs",
16+
"types": "./dist/types.d.ts",
17+
"files": [
18+
"dist"
19+
],
20+
"scripts": {
21+
"prepack": "nuxt-module-build",
22+
"dev": "nuxi dev playground",
23+
"dev:build": "nuxi build playground",
24+
"dev:prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare playground",
25+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
26+
"lint": "eslint .",
27+
"test": "vitest run",
28+
"test:watch": "vitest watch"
29+
},
30+
"dependencies": {
31+
"@nuxt/kit": "^3.7.3"
32+
},
33+
"devDependencies": {
34+
"@types/node": "^18.17.17",
35+
"@nuxt/devtools": "latest",
36+
"@nuxt/eslint-config": "^0.2.0",
37+
"@nuxt/module-builder": "^0.5.1",
38+
"@nuxt/schema": "^3.7.3",
39+
"@nuxt/test-utils": "^3.7.3",
40+
"changelogen": "^0.5.5",
41+
"eslint": "^8.49.0",
42+
"nuxt": "^3.7.3",
43+
"vitest": "^0.33.0"
44+
}
45+
}

playground/app.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<div>
3+
Nuxt module playground!
4+
</div>
5+
</template>
6+
7+
<script setup>
8+
</script>

playground/nuxt.config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default defineNuxtConfig({
2+
modules: ['../src/module'],
3+
myModule: {},
4+
devtools: { enabled: true }
5+
})

playground/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "my-module-playground",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "nuxi dev",
7+
"build": "nuxi build",
8+
"generate": "nuxi generate"
9+
},
10+
"devDependencies": {
11+
"nuxt": "latest"
12+
}
13+
}

playground/server/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../.nuxt/tsconfig.server.json"
3+
}

playground/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

src/module.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
2+
3+
// Module options TypeScript interface definition
4+
export interface ModuleOptions {}
5+
6+
export default defineNuxtModule<ModuleOptions>({
7+
meta: {
8+
name: 'my-module',
9+
configKey: 'myModule'
10+
},
11+
// Default configuration options of the Nuxt module
12+
defaults: {},
13+
setup (options, nuxt) {
14+
const resolver = createResolver(import.meta.url)
15+
16+
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
17+
addPlugin(resolver.resolve('./runtime/plugin'))
18+
}
19+
})

src/runtime/plugin.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineNuxtPlugin } from '#app'
2+
3+
export default defineNuxtPlugin((nuxtApp) => {
4+
console.log('Plugin injected by my-module!')
5+
})

test/basic.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { fileURLToPath } from 'node:url'
3+
import { setup, $fetch } from '@nuxt/test-utils'
4+
5+
describe('ssr', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
8+
})
9+
10+
it('renders the index page', async () => {
11+
// Get response to a server-rendered page with `$fetch`.
12+
const html = await $fetch('/')
13+
expect(html).toContain('<div>basic</div>')
14+
})
15+
})

test/fixtures/basic/app.vue

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div>basic</div>
3+
</template>
4+
5+
<script setup>
6+
</script>

test/fixtures/basic/nuxt.config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import MyModule from '../../../src/module'
2+
3+
export default defineNuxtConfig({
4+
modules: [
5+
MyModule
6+
]
7+
})

test/fixtures/basic/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"private": true,
3+
"name": "basic",
4+
"type": "module"
5+
}

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

0 commit comments

Comments
 (0)