Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e4b9cd8

Browse files
ChangJoo-Parkkevinmarreclmichelin
authored
feat: add typescript support using typescript-build (#328)
* typescript support using typescript-build * Remove trailing comma * remove @types/node * Add default / ts-runtime for none server + ts * set lang="ts" when using typescript * Remove ts-node * @nuxt/typescript-build version to 0.1.11 * Update ts script tag * Add typescript nuxt cookbook when completed * Using tsconfig.json using always when selected ts * only suggestion jsconfig.json when js users * fix typo * using js by default * tsconfig / jsconfig settings * add closing tag for ts * Delete package-lock.json * Update template/nuxt/pages/index.vue Co-Authored-By: Kevin Marrec <[email protected]> * support eslint when TypeScript. * set false tsRuntime when select TypeScript * support jest with typescript * Update saofile.js * Update template/tsconfig.json Co-Authored-By: Louis-Marie Michelin <[email protected]> * Add language and runtime to prompts.js * Update TypeScript relative package versions * @nuxt/core needs eslint-module * Update tsconfig.json * Update README for TypeScript * Install eslint-module when eslint && !typesciprt * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/tsconfig.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update template/_package.json Co-Authored-By: Kevin Marrec <[email protected]> * Update .eslintignore Add jest.config.js * Update template/nuxt/nuxt.config.js * Update template/nuxt/nuxt.config.js * bump some packages versions Co-authored-by: Kevin Marrec <[email protected]> Co-authored-by: Louis-Marie Michelin <[email protected]>
1 parent ddcdcb7 commit e4b9cd8

File tree

10 files changed

+127
-2
lines changed

10 files changed

+127
-2
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
_*.js
22
template/nuxt/pages/index.vue
33
template/frameworks/iview/pages/index.vue
4+
template/frameworks/jest/jest.config.js

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ yarn create nuxt-app <my-project>
3636
1. Choose the package manager
3737
- Yarn
3838
- Npm
39+
1. Choose programming language
40+
- JavaScript
41+
- TypeScript
3942
1. Choose your favorite UI framework:
4043
- None (feel free to add one later)
4144
- [Ant Design Vue](https://github.com/vueComponent/ant-design-vue)
@@ -58,6 +61,9 @@ yarn create nuxt-app <my-project>
5861
- [Hapi](https://github.com/hapijs/hapi)
5962
- [Koa](https://github.com/koajs/koa)
6063
- [Micro](https://github.com/zeit/micro)
64+
1. Choose the runtime for TypeScript (if you choose TypeScript)
65+
- Default
66+
- [@nuxt/typescript-runtime](https://github.com/nuxt/typescript)
6167
1. Choose Nuxt.js modules:
6268
- [Axios](https://github.com/nuxt-community/axios-module)
6369
- [Progressive Web App (PWA) Support](https://github.com/nuxt-community/pwa-module)

prompts.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ module.exports = [
1818
default: '{gitUser.name}',
1919
store: true
2020
},
21+
{
22+
name: 'language',
23+
message: 'Choose programming language',
24+
choices: [
25+
{ name: 'JavaScript', value: 'js' },
26+
{ name: 'TypeScript', value: 'ts' }
27+
],
28+
type: 'list',
29+
default: 'js'
30+
},
2131
{
2232
name: 'pm',
2333
message: 'Choose the package manager',
@@ -66,6 +76,16 @@ module.exports = [
6676
],
6777
default: 'none'
6878
},
79+
{
80+
name: 'runtime',
81+
message: 'Choose the runtime for TypeScript',
82+
type: 'list',
83+
choices: [
84+
{ name: 'Default', value: 'none' },
85+
{ name: '@nuxt/typescript-runtime', value: 'ts-runtime' }
86+
],
87+
when: answers => answers.language === 'ts' && answers.server === 'none'
88+
},
6989
{
7090
name: 'features',
7191
message: 'Choose Nuxt.js modules',

saofile.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const rootDir = __dirname
88
module.exports = {
99
prompts: require('./prompts'),
1010
templateData () {
11+
const typescript = this.answers.language.includes('ts')
12+
const tsRuntime = this.answers.runtime && this.answers.runtime.includes('ts-runtime')
1113
const pwa = this.answers.features.includes('pwa')
1214
const eslint = this.answers.linter.includes('eslint')
1315
const prettier = this.answers.linter.includes('prettier')
@@ -23,6 +25,8 @@ module.exports = {
2325
const edge = cliOptions.edge ? '-edge' : ''
2426

2527
return {
28+
typescript,
29+
tsRuntime,
2630
pwa,
2731
eslint,
2832
prettier,
@@ -87,6 +91,7 @@ module.exports = {
8791
patterns: files
8892
})
8993
}
94+
9095
actions.push({
9196
type: 'add',
9297
files: '**',
@@ -101,6 +106,7 @@ module.exports = {
101106
'_.eslintrc.js': 'linter.includes("eslint")',
102107
'_.prettierrc': 'linter.includes("prettier")',
103108
'_jsconfig.json': 'devTools.includes("jsconfig.json")',
109+
'tsconfig.json': 'language.includes("ts")',
104110
'semantic.yml': 'devTools.includes("semantic-pull-requests")',
105111
'.env': 'features.includes("dotenv")',
106112
'_stylelint.config.js': 'linter.includes("stylelint")'
@@ -168,5 +174,9 @@ module.exports = {
168174
console.log(chalk` {bold To test:}\n`)
169175
console.log(chalk`${cdMsg}\t{cyan ${pmRun} test}\n`)
170176
}
177+
178+
if (this.answers.language.includes('ts')) {
179+
console.log(chalk`\n {bold For TypeScript users.} \n\n See : https://typescript.nuxtjs.org/cookbook/components/`)
180+
}
171181
}
172182
}

template/_.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ module.exports = {
99
use: true
1010
},
1111
<%_ } _%>
12+
<%_ if (!typescript) { _%>
1213
parserOptions: {
1314
parser: 'babel-eslint'
1415
},
16+
<%_ } _%>
1517
extends: [
18+
<%_ if (typescript) { _%>
19+
'@nuxtjs/eslint-config-typescript',
20+
<%_ } else {_%>
1621
'@nuxtjs',
22+
<%_ } _%>
1723
<%_ if (prettier) { _%>
1824
'prettier',
1925
'prettier/vue',

template/_package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
"private": true,
77
"scripts": {
88
<%_ if (server === 'none') { _%>
9+
<%_ if (tsRuntime) { _%>
10+
"dev": "nuxt-ts",
11+
"build": "nuxt-ts build",
12+
"generate": "nuxt-ts generate",
13+
"start": "nuxt-ts start",
14+
<%_ } else { _%>
915
"dev": "nuxt",
1016
"build": "nuxt build",
1117
"start": "nuxt start",
1218
"generate": "nuxt generate",
19+
<%_ } _%>
1320
<%_ } else if (server === 'adonis') { _%>
1421
"serve:dev": "<%= pmRun %> dev",
1522
"dev": "nodemon --watch app --watch bootstrap --watch config --watch .env -x node server.js",
@@ -58,6 +65,9 @@
5865
<%_ } else { _%>
5966
"nuxt": "^2.0.0",
6067
<%_ } _%>
68+
<%_ if (tsRuntime) { _%>
69+
"@nuxt/typescript-runtime": "^0.4.0",
70+
<%_ } _%>
6171
<%_ if (server !== 'none') { _%>
6272
"cross-env": "^5.2.0",
6373
<%_ } _%>
@@ -125,6 +135,9 @@
125135
<%_ if (server !== 'none') { _%>
126136
"nodemon": "^1.18.9",
127137
<%_ } _%>
138+
<%_ if (typescript) { _%>
139+
"@nuxt/typescript-build": "^0.6.0",
140+
<%_ } _%>
128141
<%_ if (ui === 'tailwind') { _%>
129142
"@nuxtjs/tailwindcss": "^1.0.0",
130143
<%_ } else if (ui === 'vuetify') { _%>
@@ -133,7 +146,11 @@
133146
"framevuerk-builder": "^2.0.2",
134147
<%_ } _%>
135148
<%_ if (eslint) { _%>
149+
<%_ if (typescript) { _%>
150+
"@nuxtjs/eslint-config-typescript": "^1.0.0",
151+
<%_ } else { _%>
136152
"@nuxtjs/eslint-config": "^2.0.0",
153+
<%_ } _%>
137154
"@nuxtjs/eslint-module": "^1.0.0",
138155
"babel-eslint": "^10.0.1",
139156
"eslint": "^6.1.0",
@@ -159,6 +176,9 @@
159176
"babel-jest": "^24.1.0",
160177
"jest": "^24.1.0",
161178
"vue-jest": "^4.0.0-0",
179+
<%_ if (typescript) { _%>
180+
"ts-jest": "^25.0.0",
181+
<%_ } _%>
162182
<%_ } else if (test === 'ava') { _%>
163183
"ava": "^3.0.0",
164184
"@ava/babel": "^1.0.0",

template/frameworks/jest/jest.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ module.exports = {
44
'^~/(.*)$': '<rootDir>/$1',
55
'^vue$': 'vue/dist/vue.common.js'
66
},
7-
moduleFileExtensions: ['js', 'vue', 'json'],
7+
moduleFileExtensions: [
8+
<%_ if (typescript) { _%>
9+
'ts',
10+
<%_ } _%>
11+
'js',
12+
'vue',
13+
'json'
14+
],
815
transform: {
16+
<%_ if (typescript) { _%>
17+
"^.+\\.ts$": "ts-jest",
18+
<%_ } _%>
919
'^.+\\.js$': 'babel-jest',
1020
'.*\\.(vue)$': 'vue-jest'
1121
},

template/nuxt/nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ module.exports = {
8787
** Nuxt.js dev-modules
8888
*/
8989
buildModules: [
90-
<%_ if (eslint) { _%>
90+
<%_ if (typescript) {_%>
91+
'@nuxt/typescript-build',
92+
<%_ } _%>
93+
<%_ if (eslint && !typescript) { _%>
9194
// Doc: https://github.com/nuxt-community/eslint-module
9295
'@nuxtjs/eslint-module',
9396
<%_ } _%>

template/nuxt/pages/index.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
</div>
2929
</template>
3030

31+
<%_ if (typescript) { _%>
32+
<script lang="ts">
33+
import Vue from 'vue'
34+
import Logo from '~/components/Logo.vue'
35+
36+
export default Vue.extend({
37+
components: {
38+
Logo
39+
}
40+
})
41+
</script>
42+
<%_ } else { _%>
3143
<script>
3244
import Logo from '~/components/Logo.vue'
3345

@@ -37,6 +49,7 @@ export default {
3749
}
3850
}
3951
</script>
52+
<%_ } _%>
4053

4154
<style>
4255
<%_ if (ui === 'tailwind') { _%>

template/tsconfig.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "esnext",
5+
"moduleResolution": "node",
6+
"lib": [
7+
"esnext",
8+
"esnext.asynciterable",
9+
"dom"
10+
],
11+
"esModuleInterop": true,
12+
"allowJs": true,
13+
"sourceMap": true,
14+
"strict": true,
15+
"noEmit": true,
16+
"experimentalDecorators": true,
17+
"baseUrl": ".",
18+
"paths": {
19+
"~/*": [
20+
"./*"
21+
],
22+
"@/*": [
23+
"./*"
24+
]
25+
},
26+
"types": [
27+
"@types/node",
28+
"@nuxt/types"
29+
]
30+
},
31+
"exclude": [
32+
"node_modules",
33+
".nuxt",
34+
"dist"
35+
]
36+
}

0 commit comments

Comments
 (0)