# unplugin-scripts

> Register global imports on demand for Vite and Webpack

Latest version **0.0.3** (published 2023-05-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install unplugin-scripts
pnpm add unplugin-scripts
yarn add unplugin-scripts
bun add unplugin-scripts
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2023-05-05 |
| First published | 2023-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 26 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tuimao |
| Keywords | unplugin, vite, webpack, rollup, transform |

## Links

- npm: https://www.npmjs.com/package/unplugin-scripts
- Repository: https://github.com/antfu/unplugin-scripts
- Homepage: https://github.com/antfu/unplugin-scripts#readme
- Issues: https://github.com/antfu/unplugin-scripts/issues
- npm.io page: https://npm.io/package/unplugin-scripts

## Dependencies (1)

- [unplugin](https://npm.io/package/unplugin.md) ^1.0.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2023-05-05
- 0.0.2 — 2023-04-28

## README

# unplugin-scripts

Better use of scripts for Vite, Webpack, Rollup and esbuild. With TypeScript support. Powered by [unplugin](https://github.com/unjs/unplugin).


## Install

```bash
npm i unplugin-scripts
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Scripts from 'unplugin-scripts/vite'

export default defineConfig({
  plugins: [
    Scripts([/* options */]),
  ],
})
```

Example: [`playground/`](./playground/)

<br></details>

<details>
<summary>Rollup</summary><br>

```ts
// rollup.config.js
import Scripts from 'unplugin-scripts/rollup'

export default {
  plugins: [
    Scripts([/* options */]),
  ],
}
```

<br></details>


<details>
<summary>Webpack</summary><br>

```ts
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-scripts/webpack')([/* options */])
  ]
}
```

<br></details>

<details>
<summary>Nuxt</summary><br>

```ts
// nuxt.config.js
export default {
  buildModules: [
    ['unplugin-scripts/nuxt', [/* options */]],
  ],
}
```

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)

<br></details>

<details>
<summary>Vue CLI</summary><br>

```ts
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-scripts/webpack')([/* options */]),
    ],
  },
}
```

<br></details>

<details>
<summary>esbuild</summary><br>

```ts
// esbuild.config.js
import { build } from 'esbuild'
import Scripts from 'unplugin-scripts/esbuild'

build({
  plugins: [Scripts()],
})
```

<br></details>

## Basic for Vite

```ts
// vite.config.ts
import Scripts from 'unplugin-scripts/vite'

function clear() {
  // ...
}

export default defineConfig(({ command }) => {
  return {
    plugins: [
      Scripts([
        // only execute once
        { script: 'node scripts/update.js' },
        // continuously executing scripts
        { script: 'api-generate', interval: 100000 },
        // only build execute
        {
          script: 'vue-tsc',
          invoke: () => command === 'prod'
        },
        // execute function
        { script: clear },
      ]),
    ],
  }
})
```

## License

[MIT](./LICENSE) License © 2023 [Hairyf](https://github.com/hairyf)

---
_Source: https://npm.io/package/unplugin-scripts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
