Visitar URL original
feat: init · unplugin/unplugin-auto-import@6a5648f · GitHub
Skip to content

Commit 6a5648f

Browse files
committed
feat: init
0 parents  commit 6a5648f

44 files changed

Lines changed: 6642 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintignore‎

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

‎.eslintrc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"env": {
3+
"jest": true
4+
},
5+
"extends": ["@antfu"],
6+
"plugins": ["jest"],
7+
"rules": {}
8+
}

‎.github/FUNDING.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [antfu]

‎.github/workflows/release.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: '14'
18+
registry-url: https://registry.npmjs.org/
19+
- run: npm i -g pnpm @antfu/ni
20+
- run: nci
21+
- run: nr test --if-present
22+
# - run: npm publish --access public
23+
# env:
24+
# NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
25+
- run: npx conventional-github-releaser -p angular
26+
env:
27+
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}

‎.github/workflows/test.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
9+
pull_request:
10+
branches:
11+
- main
12+
- master
13+
14+
jobs:
15+
build:
16+
runs-on: ${{ matrix.os }}
17+
18+
strategy:
19+
matrix:
20+
node-version: [12.x, 14.x]
21+
os: [ubuntu-latest, windows-latest, macos-latest]
22+
fail-fast: false
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v1
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
32+
- name: Setup
33+
run: npm i -g pnpm @antfu/ni
34+
35+
- name: Install
36+
run: nci
37+
38+
# - name: Lint
39+
# run: nr lint --if-present
40+
41+
- name: Test
42+
run: nr test --if-present

‎.gitignore‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# parcel-bundler cache (https://parceljs.org/)
63+
.cache
64+
65+
# next.js build output
66+
.next
67+
68+
# nuxt.js build output
69+
.nuxt
70+
71+
# Nuxt generate
72+
dist
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless
79+
80+
# IDE
81+
.idea
82+
global-imports.d.ts

‎.npmrc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore-workspace-root-check=true
2+
shamefully-hoist=true

‎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) 2021 Anthony Fu <https://github.com/antfu>
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: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# unplugin-auto-import
2+
3+
[![NPM version](https://img.shields.io/npm/v/unplugin-auto-import?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-auto-import)
4+
5+
Register global imports on demand for Vite, Rollup, and Webpack. With TypeScript supports. Powered by [unplugin](https://github.com/unjs/unplugin).
6+
7+
## Install
8+
9+
```bash
10+
npm i unplugin-auto-import
11+
```
12+
13+
<details>
14+
<summary>Vite</summary><br>
15+
16+
```ts
17+
// vite.config.ts
18+
import AutoImport from 'unplugin-auto-import/vite'
19+
20+
export default defineConfig({
21+
plugins: [
22+
AutoImport({ /* options */ }),
23+
],
24+
})
25+
```
26+
27+
Example: [`playground/`](./playground/)
28+
29+
<br></details>
30+
31+
<details>
32+
<summary>Rollup</summary><br>
33+
34+
```ts
35+
// rollup.config.js
36+
import AutoImport from 'unplugin-auto-import/rollup'
37+
38+
export default {
39+
plugins: [
40+
AutoImport({ /* options */ }),
41+
// other plugins
42+
],
43+
}
44+
```
45+
46+
<br></details>
47+
48+
49+
<details>
50+
<summary>Webpack</summary><br>
51+
52+
```ts
53+
// webpack.config.js
54+
module.exports = {
55+
/* ... */
56+
plugins: [
57+
require('unplugin-auto-import/webpack')({ /* options */ })
58+
]
59+
}
60+
```
61+
62+
<br></details>
63+
64+
<details>
65+
<summary>Nuxt</summary><br>
66+
67+
```ts
68+
// nuxt.config.js
69+
export default {
70+
buildModules: [
71+
['unplugin-auto-import/nuxt', { /* options */ }],
72+
],
73+
}
74+
```
75+
76+
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
77+
78+
<br></details>
79+
80+
<details>
81+
<summary>Vue CLI</summary><br>
82+
83+
```ts
84+
// vue.config.js
85+
module.exports = {
86+
configureWebpack: {
87+
plugins: [
88+
require('unplugin-auto-import/webpack')({ /* options */ }),
89+
],
90+
},
91+
}
92+
```
93+
94+
<br></details>
95+
96+
97+
98+
## Configuration
99+
100+
```ts
101+
AutoImport({
102+
// targets to transform
103+
include: [
104+
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
105+
/\.vue\??/, // .vue
106+
],
107+
108+
// global imports to register
109+
imports: [
110+
// presets
111+
'vue',
112+
'vue-router',
113+
// custom
114+
{
115+
'@vueuse/core': [
116+
'useMouse'
117+
],
118+
'[package-name]': [
119+
'[import-names]',
120+
// alias
121+
['[from]', '[alias]']
122+
]
123+
}
124+
],
125+
})
126+
```
127+
128+
Refer to the [type definitions](./src/types.ts) for more options.
129+
130+
## FAQ
131+
132+
### Compare to [`vue-global-api`](https://github.com/antfu/vue-global-api)
133+
134+
You can think this plugin as a successor of `vue-global-api`, which offers much more flexibility and it's no longer bound to Vue exclusively. Now you can use it with any libraries you want (e.g. React).
135+
136+
###### Pros
137+
138+
- Flexible and customizable
139+
- Tree-shakable (on-demand transforming)
140+
- No global population
141+
142+
###### Cons
143+
144+
- Relying on build tools integrations (while `vue-global-api` is pure runtime) - but hey, we have supported quite a few of them already!
145+
146+
## Sponsors
147+
148+
<p align="center">
149+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
150+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
151+
</a>
152+
</p>
153+
154+
## License
155+
156+
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)

‎jest.config.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
roots: [
3+
'<rootDir>/test',
4+
],
5+
testMatch: [
6+
'**/__tests__/**/*.+(ts|tsx|js)',
7+
'**/?(*.)+(spec|test).+(ts|tsx|js)',
8+
],
9+
transform: {
10+
'^.+\\.(ts|tsx)$': 'ts-jest',
11+
},
12+
}

0 commit comments

Comments
 (0)