Skip to content

Commit e9bf437

Browse files
committed
chore: init
0 parents  commit e9bf437

File tree

10 files changed

+1922
-0
lines changed

10 files changed

+1922
-0
lines changed

.gitattributes

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Git attributes
2+
# https://git-scm.com/docs/gitattributes
3+
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes
4+
5+
# Normalize line endings for all files that git determines to be text.
6+
# https://git-scm.com/docs/gitattributes#gitattributes-Settostringvalueauto
7+
* text=auto
8+
9+
# Normalize line endings to LF on checkin, and do NOT convert to CRLF when checking-out on Windows.
10+
# https://git-scm.com/docs/gitattributes#gitattributes-Settostringvaluelf
11+
*.txt text eol=lf
12+
*.html text eol=lf
13+
*.md text eol=lf
14+
*.css text eol=lf
15+
*.scss text eol=lf
16+
*.map text eol=lf
17+
*.js text eol=lf
18+
*.jsx text eol=lf
19+
*.ts text eol=lf
20+
*.tsx text eol=lf
21+
*.json text eol=lf
22+
*.yml text eol=lf
23+
*.yaml text eol=lf
24+
*.xml text eol=lf
25+
*.svg text eol=lf

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: lts/*
22+
23+
- run: npx changelogithub
24+
env:
25+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Git ignore
2+
# https://git-scm.com/docs/gitignore
3+
4+
# Miscellaneous
5+
*~
6+
*#
7+
.DS_STORE
8+
Thumbs.db
9+
.netbeans
10+
nbproject
11+
.node_history
12+
13+
# IDEs & Text Editors
14+
.idea
15+
.sublime-*
16+
.vscode/settings.json
17+
.netbeans
18+
nbproject
19+
20+
# Temporary files
21+
.tmp
22+
.temp
23+
.grunt
24+
.lock-wscript
25+
26+
# Logs
27+
/logs
28+
*.log
29+
30+
# Runtime data
31+
pids
32+
*.pid
33+
*.seed
34+
35+
# Dependencies
36+
node_modules
37+
38+
# Build output
39+
/lib
40+
41+
# Test output
42+
/.nyc_output
43+
/coverage
44+
dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Bobbie Goede (@BobbieGoede)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[![](https://img.shields.io/npm/v/nuxt-define/latest.svg?style=flat&label=npm&colorA=18181B)](https://npmjs.com/package/nuxt-define)
2+
[![](https://img.shields.io/npm/dm/nuxt-define?style=flat&colorA=18181B&color=blue)](https://npmjs.com/package/nuxt-define)
3+
4+
# Nuxt Define
5+
6+
One utility function for module authors to define compiler constants for all builders supported by Nuxt.
7+
8+
Supported builders:
9+
* Vite
10+
* Webpack
11+
* Rspack
12+
13+
## Installation
14+
15+
```bash
16+
npm i nuxt-define
17+
```
18+
19+
## Usage
20+
21+
```ts
22+
// src/module.ts
23+
import { addDefinePlugin } from 'nuxt-define'
24+
25+
export default defineNuxtModule({
26+
setup() {
27+
addDefinePlugin({
28+
'__MY_CONSTANT__': JSON.stringify('myValue'),
29+
'__SOME_FEATURE_FLAG__': JSON.stringify(false),
30+
})
31+
}
32+
})
33+
```
34+
35+
```ts
36+
// src/runtime/foo.ts
37+
export function foo() {
38+
console.log(__MY_CONSTANT__) // 'myValue'
39+
40+
if (__SOME_FEATURE_FLAG__) {
41+
// expensive computation
42+
// omitted from final build if compiler constant is false
43+
}
44+
}
45+
46+
```
47+
48+
## Why?
49+
50+
Nuxt supports multiple builders, and each builder has its own way of defining constants. This module abstracts that complexity and provides a unified API to define compiler constants that work across all supported builders.
51+
52+
An added bonus is that you do not need to explicitly add these builders as dev dependencies, keeping your Github notifications free of renovate PR noise.
53+
54+
## Sponsors
55+
56+
<p align="center">
57+
<a href="https://raw.githubusercontent.com/bobbiegoede/static/main/sponsors.svg">
58+
<img src="https://raw.githubusercontent.com/bobbiegoede/static/main/sponsors.svg" />
59+
</a>
60+
</p>
61+

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "nuxt-define",
3+
"version": "0.0.1",
4+
"description": "One utility function for module authors to define compiler constants for all builders supported by Nuxt.",
5+
"type": "module",
6+
"license": "MIT",
7+
"funding": "https://github.com/sponsors/bobbiegoede",
8+
"keywords": [
9+
"nuxt",
10+
"module"
11+
],
12+
"author": {
13+
"name": "Bobbie Goede",
14+
"email": "bobbiegoede@gmail.com"
15+
},
16+
"contributors": [
17+
{
18+
"name": "Bobbie Goede (@BobbieGoede)"
19+
}
20+
],
21+
"main": "./dist/index.js",
22+
"module": "./dist/index.js",
23+
"types": "./dist/index.d.ts",
24+
"exports": {
25+
".": "./dist/index.js",
26+
"./package.json": "./package.json"
27+
},
28+
"files": [
29+
"dist"
30+
],
31+
"scripts": {
32+
"build": "tsdown",
33+
"release": "pnpm run bumpp && pnpm publish"
34+
},
35+
"packageManager": "pnpm@10.11.1",
36+
"devDependencies": {
37+
"@nuxt/kit": "^3.17.5",
38+
"@rspack/core": "^1.3.15",
39+
"bumpp": "^10.1.1",
40+
"tsdown": "^0.12.7",
41+
"typescript": "^5.8.3",
42+
"webpack": "^5.99.9"
43+
}
44+
}

0 commit comments

Comments
 (0)