Skip to content

Commit 48d278b

Browse files
committed
initial commit
0 parents  commit 48d278b

File tree

13 files changed

+10120
-0
lines changed

13 files changed

+10120
-0
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"@nuxtjs/eslint-config-typescript"
4+
]
5+
}

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
ci:
13+
runs-on: ${{ matrix.os }}
14+
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest]
18+
node: [14]
19+
20+
steps:
21+
- uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node }}
24+
25+
- name: checkout
26+
uses: actions/checkout@master
27+
28+
- name: cache node_modules
29+
uses: actions/cache@v1
30+
with:
31+
path: node_modules
32+
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
33+
34+
- name: Install dependencies
35+
if: steps.cache.outputs.cache-hit != 'true'
36+
run: yarn
37+
38+
- name: Lint
39+
run: yarn lint
40+
41+
# - name: Test
42+
# run: yarn jest
43+
44+
# - name: Coverage
45+
# uses: codecov/codecov-action@v1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.nuxt
2+
dist
3+
node_modules
4+
*.log
5+
.idea

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) Nuxt Team
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# nuxt-swc
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![license][license-src]][license-href]
6+
7+
Replaces [babel](https://babeljs.io/) with [swc](https://github.com/swc-project/swc) using [swc-loader](https://github.com/swc-project/swc-loader) for [Nuxt](http://nuxtjs.org/).
8+
9+
## Why?
10+
11+
- Faster build (see [benchmarks](https://swc.rs/docs/benchmark-transform))
12+
- Typescript build (transpile-only)
13+
14+
## Current limitations
15+
16+
This module is an experiment. Some features might be broken.
17+
18+
- Check [comparison with babel](https://swc.rs/docs/comparison-babel/)
19+
- Sourcemap is disabled
20+
- Babel options
21+
22+
## Usage
23+
24+
Install `nuxt-swc` as `devDependency` of project:
25+
26+
```sh
27+
yarn add --dev nuxt-swc
28+
# or
29+
npm i -D nuxt-swc
30+
```
31+
32+
Add `nuxt-swc` to `buildModules` in `nuxt.config`:
33+
34+
```js
35+
// nuxt.config
36+
export default {
37+
buildModules: [
38+
'nuxt-swc'
39+
]
40+
}
41+
```
42+
43+
## Alternatives
44+
45+
- [nuxt-esbuild](https://github.com/galvez/nuxt-esbuild-module)
46+
47+
## 📑 License
48+
49+
[MIT License](./LICENSE)
50+
51+
<!-- Badges -->
52+
[npm-version-src]: https://flat.badgen.net/npm/v/nuxt-swc
53+
[npm-version-href]: https://npmjs.com/package/nuxt-swc
54+
[npm-downloads-src]: https://flat.badgen.net/npm/dm/nuxt-swc
55+
[npm-downloads-href]: https://npmjs.com/package/nuxt-swc
56+
[license-src]: https://flat.badgen.net/github/license/pi0/nuxt-swc
57+
[license-href]: https://npmjs.com/package/nuxt-swc

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "nuxt-swc",
3+
"version": "0.0.0",
4+
"repository": "nuxt-contrib/nuxt-swc",
5+
"license": "MIT",
6+
"main": "./dist/index.js",
7+
"files": [
8+
"dist"
9+
],
10+
"scripts": {
11+
"build": "siroc build",
12+
"dev": "nuxt dev test/fixture",
13+
"lint": "eslint --ext .ts .",
14+
"prepack": "yarn build",
15+
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
16+
"test": "yarn lint"
17+
},
18+
"dependencies": {
19+
"@swc/core": "^1.2.58",
20+
"defu": "^5.0.0"
21+
},
22+
"devDependencies": {
23+
"@nuxtjs/eslint-config-typescript": "^6.0.0",
24+
"eslint": "^7.22.0",
25+
"nuxt": "^2.15.3",
26+
"siroc": "^0.10.1",
27+
"standard-version": "^9.1.1",
28+
"swc-loader": "^0.1.14"
29+
}
30+
}

renovate.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": [
3+
"@nuxtjs"
4+
],
5+
"ignoreDeps": [
6+
"postcss-loader"
7+
]
8+
}

src/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import defu from 'defu'
2+
import { name, version } from '../package.json'
3+
4+
function swcModule () {
5+
const { nuxt } = this
6+
7+
const swcOptions = defu(nuxt.options.build.swc, {
8+
// sync: true,
9+
sourceMaps: false,
10+
jsc: {
11+
parser: {
12+
dynamicImport: true
13+
}
14+
}
15+
})
16+
17+
const swcTSOptions = defu(swcOptions, {
18+
jsc: {
19+
parser: {
20+
syntax: 'typescript',
21+
dynamicImport: true
22+
}
23+
}
24+
})
25+
26+
nuxt.hook('webpack:config', (configs) => {
27+
for (const config of configs) {
28+
config.module.rules = [
29+
{
30+
test: /\.m?[jt]sx?$/i,
31+
use: {
32+
loader: require.resolve('swc-loader'),
33+
options: swcOptions
34+
}
35+
},
36+
{
37+
test: /\.m?[jt]sx?$/i,
38+
use: {
39+
loader: require.resolve('swc-loader'),
40+
options: swcTSOptions
41+
}
42+
},
43+
...config.module.rules.filter(r => !'.js'.match(r.test))
44+
]
45+
}
46+
})
47+
}
48+
49+
swcModule.meta = {
50+
name,
51+
version
52+
}
53+
54+
export default swcModule

test/fixture/nuxt.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import nuxtSWC from '../../src'
2+
3+
export default {
4+
buildModules: [
5+
nuxtSWC
6+
],
7+
plugins: [
8+
'~/plugins/test.ts'
9+
]
10+
}

test/fixture/pages/index.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div>
3+
{{ hello }}
4+
</div>
5+
</template>
6+
7+
<script lang="ts">
8+
export default {
9+
data () {
10+
const hello: String = 'Hello World'
11+
return {
12+
hello
13+
}
14+
}
15+
}
16+
</script>

0 commit comments

Comments
 (0)