Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit c42dbed

Browse files
committed
feat: init
0 parents  commit c42dbed

File tree

9 files changed

+12466
-0
lines changed

9 files changed

+12466
-0
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
extends: [
3+
'@cyansalt/preset',
4+
],
5+
}

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.DS_Store
2+
node_modules
3+
4+
# Log files
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
9+
# Editor directories and files
10+
.idea
11+
.vscode
12+
*.suo
13+
*.ntvs*
14+
*.njsproj
15+
*.sln
16+
*.sw*
17+
*.cpuprofile

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry=https://registry.npmjs.org
2+
legacy-peer-deps=true
3+
message=chore: release v%s

.release-it.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"git": {
3+
"commitMessage": "chore: release v${version}",
4+
"tagName": "v${version}"
5+
},
6+
"github": {
7+
"release": true,
8+
"releaseName": "v${version}"
9+
},
10+
"plugins": {
11+
"@release-it/conventional-changelog": {
12+
"preset": "conventionalcommits",
13+
"infile": "CHANGELOG.md"
14+
}
15+
}
16+
}

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2020-present CyanSalt
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vue2-script-setup-loader
2+
3+
Bring [`<script setup>`](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to Vue 2.
4+
5+
It's really just another wrapper for [`unplugin-vue2-script-setup`](https://github.com/antfu/unplugin-vue2-script-setup).
6+
7+
### Why not just use `unplugin-vue2-script-setup` ?
8+
9+
Because Unplugin uses non-serializable loader options when adding functionality to Webpack, which will cause the worker of `thread-loader` to not work properly (e.g. with the default configuration of the Vue CLI).
10+
11+
Fortunately, it can be avoided by using a loader that is handled completely independently, and it is especially easy since `unplugin-vue2-script-setup` only uses the `transform` API. The only caveat is that you may need to manage the files you wish to transform manually, including `.vue` or `.js/ts` files.
12+
13+
## Installation
14+
15+
```shell
16+
npm install -D vue2-script-setup-loader
17+
npm i @vue/composition-api
18+
```
19+
20+
Install [`@vue/composition-api`](https://github.com/vuejs/composition-api) in your App's entry (it enables the `setup()` hook):
21+
22+
```javascript
23+
import Vue from 'vue'
24+
import VueCompositionAPI from '@vue/composition-api'
25+
26+
Vue.use(VueCompositionAPI)
27+
```
28+
29+
## Usage
30+
31+
```javascript
32+
// webpack.config.js
33+
module.exports = {
34+
// ...
35+
module: {
36+
rules: [
37+
{
38+
test: /\.vue$/i,
39+
use: [
40+
{
41+
loader: 'vue-loader',
42+
},
43+
// Add it here
44+
{
45+
loader: 'vue2-script-setup-loader',
46+
},
47+
],
48+
},
49+
],
50+
},
51+
}
52+
```

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const loaderUtils = require('loader-utils')
2+
const { transform } = require('unplugin-vue2-script-setup')
3+
4+
module.exports = function loader(content, map, meta) {
5+
const callback = this.async()
6+
transform(content, this.resourcePath, loaderUtils.getOptions(this)).then(result => {
7+
if (result) {
8+
callback(null, result.code, result.map, meta)
9+
} else {
10+
callback(null, content, map, meta)
11+
}
12+
}, err => {
13+
callback(err)
14+
})
15+
}

0 commit comments

Comments
 (0)