# vue-compile

> Pre-compile each blocks of your Vue single-file components.

Latest version **1.1.2** (published 2021-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-compile
pnpm add vue-compile
yarn add vue-compile
bun add vue-compile
```

Provides the command `vue-compile`.

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-12-16 |
| First published | 2019-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 38.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 160 |
| Author | egoist |
| Maintainers | egoist |

## Links

- npm: https://www.npmjs.com/package/vue-compile
- Repository: https://github.com/egoist/vue-compile
- Homepage: https://github.com/egoist/vue-compile#readme
- Issues: https://github.com/egoist/vue-compile/issues
- npm.io page: https://npm.io/package/vue-compile

## Dependencies (19)

- [cac](https://npm.io/package/cac.md) ^6.7.2
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [joycon](https://npm.io/package/joycon.md) ^3.0.1
- [postcss](https://npm.io/package/postcss.md) ^8.2.10
- [resolve](https://npm.io/package/resolve.md) ^1.20.0
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.1.0
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.2.5
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.13.15
- [resolve-from](https://npm.io/package/resolve-from.md) ^5.0.0
- [is-binary-path](https://npm.io/package/is-binary-path.md) ^2.1.0
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.13.15
- [@vue/compiler-sfc](https://npm.io/package/@vue/compiler-sfc.md) ^3.0.11
- [postcss-load-config](https://npm.io/package/postcss-load-config.md) ^3.0.1
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) ^2.0.0
- [@babel/preset-typescript](https://npm.io/package/@babel/preset-typescript.md) ^7.13.0
- [@babel/plugin-syntax-typescript](https://npm.io/package/@babel/plugin-syntax-typescript.md) ^7.12.13

## Recent versions

- 1.1.2 (latest) — 2021-12-16
- 0.6.1-canary.17.eabb05c (canary) — 2019-07-03
- 1.1.1 — 2021-08-12
- 1.1.0 — 2021-04-18
- 1.0.0 — 2021-04-18
- 0.6.2 — 2020-10-19
- 0.6.1 — 2020-10-09
- 0.6.1-canary.17.6ca7886 — 2019-07-03
- 0.6.0 — 2019-06-11
- 0.5.3 — 2019-03-30
- 0.5.2 — 2019-03-26
- 0.5.1 — 2019-03-26
- 0.5.0 — 2019-03-26
- 0.4.0 — 2019-03-26
- 0.3.1 — 2019-01-05
- … 1 more at https://npm.io/package/vue-compile/versions

## README

# vue-compile

Compile the blocks in Vue single-file components to JS/CSS from Babel/Sass/Stylus.

## Why This Approach

We want to publish `.vue` files instead of transformed `.js` files on npm because the `.vue` file is preferred in some scenarioes, e.g. `vue-server-renderer` can inline critical CSS from `<style>` blocks.

This tool will transform each block in the `.vue` file to their standard conterparts like `sass` -> `css` so your users don't have to install additional libraries to compile it.


## Install

```bash
yarn global add vue-compile
# or
npm i -g vue-compile
```

## Usage

```bash
# normalize a .vue file
vue-compile example.vue -o output.vue
# normalize a directory
# non .vue files will be simply copied to output directory
vue-compile src -o lib
```

__Then you can publish normalized `.vue` files to npm registry without compiling them to `.js` files.__

Supported transforms (via `lang` attribute):

- `<template>` tag:
  - `html` (default)
- `<script>` tag: 
  - `babel` (default): use our default [babel preset](./lib/babel/preset.js) or your own `.babelrc`
  - `ts` `typescript`: use our default [babel preset](./lib/babel/preset.js) + `@babel/preset-typescript`
- `<style>` tag: 
  - `postcss` (default): use your own `postcss.config.js`
  - `stylus` `sass` `scss`
- Custom blocks: They are not touched.

Gotchas:

- We only handle `src` attribute for `<style>` blocks, we simply replace the extension with `.css` and remove the `lang` attribute.

<details><summary>Example</summary><br>

In:

```vue
<template>
  <div class="foo">
    {{ count }}
  </div>
</template>

<script>
export default {
  data() {
    return {
      count: 0
    }
  }
}
</script>

<style lang="scss" src="./foo.scss">

<style lang="stylus" scoped>
@import './colors.styl'

.foo 
  color: $color
</style>
```

Out:

```vue
<template>  
  <div class="foo">
    {{ count }}
  </div>
</template>

<script>
export default {
  data: function data() {
    return {
      count: 0
    };
  }
};
</script>

<style src="./foo.css">

<style scoped>
.foo {
  color: #f00;
}
</style>
```
</details>

### Compile Standalone CSS Files

CSS files like `.css` `.scss` `.sass` `.styl` will be compiled to output directory with `.css` extension, all relevant `import` statements in `.js` `.ts` or `<script>` blocks will be changed to use `.css` extension as well.

You can exclude them using the `--exclude "**/*.{css,scss,sass,styl}"` flag.

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D


## Author

**vue-compile** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/vue-compile/contributors)).

> [github.com/egoist](https://github.com/egoist) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)

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