mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
feat: externalize typescript support (#5858)
This commit is contained in:
parent
b73115e576
commit
81b5ce22ce
@ -125,7 +125,7 @@ jobs:
|
|||||||
command: yarn lint:app
|
command: yarn lint:app
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Phase 3: Unit, E2E and types tests
|
# Phase 3: Unit and E2E tests
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
test-unit:
|
test-unit:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -164,16 +164,6 @@ jobs:
|
|||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: reports/junit
|
path: reports/junit
|
||||||
|
|
||||||
test-types:
|
|
||||||
<<: *defaults
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- attach_workspace:
|
|
||||||
at: ~/project
|
|
||||||
- run:
|
|
||||||
name: Types Tests
|
|
||||||
command: yarn test:types
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Phase 4: Release (dev branch only)
|
# Phase 4: Release (dev branch only)
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@ -200,9 +190,8 @@ workflows:
|
|||||||
- lint-app: { requires: [build] }
|
- lint-app: { requires: [build] }
|
||||||
- test-unit: { requires: [build] }
|
- test-unit: { requires: [build] }
|
||||||
- test-e2e: { requires: [build] }
|
- test-e2e: { requires: [build] }
|
||||||
- test-types: { requires: [build] }
|
|
||||||
- release-commit:
|
- release-commit:
|
||||||
requires: [build, lint, lint-app, audit, test-unit, test-e2e, test-types]
|
requires: [build, lint, lint-app, audit, test-unit, test-e2e]
|
||||||
filters:
|
filters:
|
||||||
<<: *release_branches
|
<<: *release_branches
|
||||||
|
|
||||||
@ -216,9 +205,8 @@ workflows:
|
|||||||
- lint-app: { requires: [build] }
|
- lint-app: { requires: [build] }
|
||||||
- test-unit: { requires: [build] }
|
- test-unit: { requires: [build] }
|
||||||
- test-e2e: { requires: [build] }
|
- test-e2e: { requires: [build] }
|
||||||
- test-types: { requires: [build] }
|
|
||||||
- release-nightly:
|
- release-nightly:
|
||||||
requires: [build, lint, lint-app, audit, test-unit, test-e2e, test-types]
|
requires: [build, lint, lint-app, audit, test-unit, test-e2e]
|
||||||
triggers:
|
triggers:
|
||||||
- schedule:
|
- schedule:
|
||||||
cron: "0 0 * * *"
|
cron: "0 0 * * *"
|
||||||
|
@ -9,7 +9,6 @@ coverage
|
|||||||
## cofeescript
|
## cofeescript
|
||||||
examples/coffeescript/pages/index.vue
|
examples/coffeescript/pages/index.vue
|
||||||
examples/pug-stylus-coffee/
|
examples/pug-stylus-coffee/
|
||||||
examples/typescript-eslint/
|
|
||||||
# Packages
|
# Packages
|
||||||
|
|
||||||
# vue-app
|
# vue-app
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
# nuxt-ts
|
|
||||||
|
|
||||||
> Nuxt With Runtime Typescript Support
|
|
@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const boxen = require('boxen')
|
|
||||||
const chalk = require('chalk').default
|
|
||||||
|
|
||||||
const warningBox = boxen([
|
|
||||||
chalk.yellow.bold('IMPORTANT : Package deprecation'),
|
|
||||||
'',
|
|
||||||
`Nuxt TypeScript Support has been refactored to be used with ${chalk.green.bold('nuxt')} package.`,
|
|
||||||
`Which means that ${chalk.yellow.bold(`nuxt-ts`)} package is now no longer needed and is now tagged as ${chalk.yellow.bold('deprecated')}.`,
|
|
||||||
`${chalk.bold.underline('We highly recommend')} to follow the guidelines below :`,
|
|
||||||
'',
|
|
||||||
chalk.yellow.bold('Migration guide (2.5.x)'),
|
|
||||||
'',
|
|
||||||
chalk.bold('Using yarn'),
|
|
||||||
'yarn remove nuxt-ts',
|
|
||||||
'yarn add nuxt',
|
|
||||||
'yarn add -D @nuxt/typescript',
|
|
||||||
'',
|
|
||||||
chalk.bold('Using npm'),
|
|
||||||
'npm uninstall nuxt-ts',
|
|
||||||
'npm install nuxt',
|
|
||||||
'npm install -D @nuxt/typescript',
|
|
||||||
'',
|
|
||||||
` ----- ${chalk.bold('nuxt.config.ts')} -----`,
|
|
||||||
'| build: { |',
|
|
||||||
`| ${chalk.red('-- useForkTsChecker: ...')} |`,
|
|
||||||
`| ${chalk.green('++ typescript : {')} |`,
|
|
||||||
`| ${chalk.green('++ typeCheck: ...')} |`,
|
|
||||||
`| ${chalk.green('++ }')} |`,
|
|
||||||
'| } |',
|
|
||||||
' --------------------------',
|
|
||||||
'',
|
|
||||||
'Find more information in updated docs : ' + chalk.blue.underline('https://nuxtjs.org/guide/typescript')
|
|
||||||
].join('\n'), Object.assign({
|
|
||||||
borderColor: 'yellow',
|
|
||||||
borderStyle: 'round',
|
|
||||||
padding: 1,
|
|
||||||
margin: 1
|
|
||||||
})) + '\n'
|
|
||||||
|
|
||||||
process.stdout.write(warningBox)
|
|
||||||
|
|
||||||
const suffix = require('../package.json').name.includes('-edge') ? '-edge' : ''
|
|
||||||
require('@nuxt/cli' + suffix).run()
|
|
||||||
.catch((error) => {
|
|
||||||
require('consola').fatal(error)
|
|
||||||
process.exit(2)
|
|
||||||
})
|
|
@ -1,23 +0,0 @@
|
|||||||
export default {
|
|
||||||
build: false,
|
|
||||||
hooks: {
|
|
||||||
async 'build:done' (pkg) {
|
|
||||||
const mono = pkg.load('../..')
|
|
||||||
const nuxt = pkg.load('../nuxt')
|
|
||||||
|
|
||||||
await pkg.copyFilesFrom(mono, [
|
|
||||||
'LICENSE'
|
|
||||||
])
|
|
||||||
|
|
||||||
pkg.copyFieldsFrom(nuxt, [
|
|
||||||
'license',
|
|
||||||
'repository',
|
|
||||||
'contributors',
|
|
||||||
'keywords',
|
|
||||||
'collective'
|
|
||||||
])
|
|
||||||
|
|
||||||
await pkg.writePackage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "nuxt-ts",
|
|
||||||
"version": "2.8.1",
|
|
||||||
"description": "Nuxt With Runtime Typescript Support",
|
|
||||||
"keywords": [
|
|
||||||
"nuxt",
|
|
||||||
"nuxt-ts",
|
|
||||||
"nuxt.js",
|
|
||||||
"nuxt.ts",
|
|
||||||
"nuxtjs",
|
|
||||||
"nuxts",
|
|
||||||
"ssr",
|
|
||||||
"vue",
|
|
||||||
"vue isomorphic",
|
|
||||||
"vue server side",
|
|
||||||
"vue ssr",
|
|
||||||
"vue universal",
|
|
||||||
"vue versatile",
|
|
||||||
"vue.js",
|
|
||||||
"vuejs"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/nuxt/nuxt.js#readme",
|
|
||||||
"repository": "nuxt/nuxt.js",
|
|
||||||
"license": "MIT",
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Sebastien Chopin (@Atinux)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Alexandre Chopin (@alexchopin)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Pooya Parsa (@pi0)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Clark Du (@clarkdo)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Jonas Galvez (@galvez)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Alexander Lichter (@manniL)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Dmitry Molotkov (@aldarund)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Kevin Marrec (@kevinmarrec)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Pim (@pimlie)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"files": [
|
|
||||||
"bin"
|
|
||||||
],
|
|
||||||
"bin": {
|
|
||||||
"nuxt-ts": "bin/nuxt-ts.js",
|
|
||||||
"nuxts": "bin/nuxt-ts.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@nuxt/builder": "2.8.1",
|
|
||||||
"@nuxt/cli": "2.8.1",
|
|
||||||
"@nuxt/core": "2.8.1",
|
|
||||||
"@nuxt/generator": "2.8.1",
|
|
||||||
"@nuxt/loading-screen": "^0.5.2",
|
|
||||||
"@nuxt/opencollective": "^0.2.2",
|
|
||||||
"@nuxt/typescript": "2.8.1",
|
|
||||||
"@nuxt/webpack": "2.8.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0.0",
|
|
||||||
"npm": ">=3.0.0"
|
|
||||||
},
|
|
||||||
"collective": {
|
|
||||||
"url": "https://opencollective.com/nuxtjs",
|
|
||||||
"logoUrl": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
Vue: https://vuejs.org/v2/guide/render-function.html
|
Vue: https://vuejs.org/v2/guide/render-function.html
|
||||||
|
|
||||||
Also see [TSX example](https://github.com/nuxt/nuxt.js/examples/typescript-tsx)
|
Also see [TSX example](https://github.com/nuxt/typescript/examples/tsx)
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
# Nuxt.ts with PM2 example
|
|
||||||
|
|
||||||
> [pm2](http://pm2.keymetrics.io/) ia an advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, micro service management and more.
|
|
||||||
|
|
||||||
[Gracefull zero-downtime restart](https://pm2.io/doc/en/runtime/best-practices/graceful-shutdown/#graceful-start)
|
|
||||||
|
|
||||||
`ecosystem.config.js` - configuration file for pm2
|
|
||||||
|
|
||||||
`listen_timeout` option depends on your need
|
|
||||||
|
|
||||||
## Zero-downtime deployment
|
|
||||||
*all depends on your deployment method. It's just example
|
|
||||||
|
|
||||||
#### Directories:
|
|
||||||
- `$PROJECT_ROOT` - your project root path on server
|
|
||||||
- `/current` - root dir for nginx(if you are using [proxy configuration](https://nuxtjs.org/faq/nginx-proxy/))
|
|
||||||
- `/_tmp` - Temporary dir to install and build project
|
|
||||||
- `/_old` - Previous build. Can be useful for fast reverting
|
|
||||||
|
|
||||||
#### Steps:
|
|
||||||
- deploy project to $PROJECT_ROOT/_tmp
|
|
||||||
- `cd $PROJECT_ROOT/_tmp`
|
|
||||||
- `npm i`
|
|
||||||
- `nuxt build` or if you are using TypeScript `nuxt-ts build`
|
|
||||||
- `mv $PROJECT_ROOT/current $PROJECT_ROOT/_old`
|
|
||||||
- `mv $PROJECT_ROOT/_tmp $PROJECT_ROOT/current`
|
|
||||||
- `cd $PROJECT_PATH/current`
|
|
||||||
- `pm2 startOrReload ecosystem.config.js`
|
|
@ -1,13 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
apps: [
|
|
||||||
{
|
|
||||||
name: 'pm2-nuxt-typescript',
|
|
||||||
script: './node_modules/.bin/nuxt',
|
|
||||||
args: 'start',
|
|
||||||
instances: 2,
|
|
||||||
exec_mode: 'cluster',
|
|
||||||
wait_ready: true,
|
|
||||||
listen_timeout: 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
import NuxtConfiguration from '@nuxt/config'
|
|
||||||
|
|
||||||
const config: NuxtConfiguration = {
|
|
||||||
hooks: {
|
|
||||||
listen () {
|
|
||||||
if (process.send) {
|
|
||||||
process.send('ready')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"nuxt": "latest",
|
|
||||||
"ts-node": "^8.1.0",
|
|
||||||
"vue-property-decorator": "^7.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nuxt",
|
|
||||||
"build": "nuxt build",
|
|
||||||
"start": "nuxt start",
|
|
||||||
"generate": "nuxt generate"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@nuxt/typescript": "latest"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
<template>
|
|
||||||
<h1>
|
|
||||||
Hello world !
|
|
||||||
</h1>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
|
|
||||||
@Component
|
|
||||||
export default class Home extends Vue {}
|
|
||||||
</script>
|
|
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"lib": [
|
|
||||||
"esnext",
|
|
||||||
"esnext.asynciterable",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noEmit": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"~/*": [
|
|
||||||
"./*"
|
|
||||||
],
|
|
||||||
"@/*": [
|
|
||||||
"./*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"types": [
|
|
||||||
"@types/node",
|
|
||||||
"@nuxt/vue-app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: ['@typescript-eslint'],
|
|
||||||
parserOptions: {
|
|
||||||
parser: '@typescript-eslint/parser'
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
'@nuxtjs'
|
|
||||||
]
|
|
||||||
}
|
|
15
examples/typescript-eslint/.gitignore
vendored
15
examples/typescript-eslint/.gitignore
vendored
@ -1,15 +0,0 @@
|
|||||||
# Dependencies
|
|
||||||
node_modules
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
*.log*
|
|
||||||
|
|
||||||
# IDE
|
|
||||||
.idea
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
# Nuxt build
|
|
||||||
.nuxt
|
|
||||||
|
|
||||||
# Nuxt generate
|
|
||||||
dist
|
|
@ -1,33 +0,0 @@
|
|||||||
# Nuxt with TypeScript & ESLint example
|
|
||||||
|
|
||||||
Use `yarn lint` or `npm run lint` to lint your TypeScript project !
|
|
||||||
|
|
||||||
## Why ESLint and not TSLint ?
|
|
||||||
|
|
||||||
See https://eslint.org/blog/2019/01/future-typescript-eslint
|
|
||||||
|
|
||||||
##
|
|
||||||
|
|
||||||
## VSCode settings
|
|
||||||
|
|
||||||
If you're using VSCode, we recommend using these settings :
|
|
||||||
|
|
||||||
```json
|
|
||||||
"eslint.autoFixOnSave": true,
|
|
||||||
"eslint.validate": [
|
|
||||||
{
|
|
||||||
"language": "javascript",
|
|
||||||
"autoFix": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"language": "typescript",
|
|
||||||
"autoFix": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"language": "vue",
|
|
||||||
"autoFix": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
It will lint your `.js`, `.ts` & `.vue` files whenever you're saving them.
|
|
@ -1,5 +0,0 @@
|
|||||||
import NuxtConfiguration from '@nuxt/config'
|
|
||||||
|
|
||||||
const config: NuxtConfiguration = {}
|
|
||||||
|
|
||||||
export default config
|
|
@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"nuxt": "latest",
|
|
||||||
"ts-node": "^8.1.0",
|
|
||||||
"vue-property-decorator": "^7.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nuxt",
|
|
||||||
"build": "nuxt build",
|
|
||||||
"start": "nuxt start",
|
|
||||||
"generate": "nuxt generate",
|
|
||||||
"lint": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .",
|
|
||||||
"lint:fix": "yarn lint --fix",
|
|
||||||
"post-update": "yarn upgrade --latest"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@nuxt/typescript": "latest",
|
|
||||||
"@nuxtjs/eslint-config": "latest",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^1.4.2",
|
|
||||||
"eslint": "^5.14.1"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
<h1>{{ title }}</h1>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
|
|
||||||
@Component
|
|
||||||
export default class Home extends Vue {
|
|
||||||
title = 'TypeScript + ESLint example'
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"lib": [
|
|
||||||
"esnext",
|
|
||||||
"esnext.asynciterable",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noEmit": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"~/*": [
|
|
||||||
"./*"
|
|
||||||
],
|
|
||||||
"@/*": [
|
|
||||||
"./*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"types": [
|
|
||||||
"@types/node",
|
|
||||||
"@nuxt/vue-app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
# Nuxt with [TSX](https://www.typescriptlang.org/docs/handbook/jsx.html)
|
|
@ -1,14 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import styles from './styles.css'
|
|
||||||
|
|
||||||
export default Vue.extend({
|
|
||||||
beforeCreate () {
|
|
||||||
// Render Inline CSS on SSR
|
|
||||||
if ((styles as any).__inject__) {
|
|
||||||
(styles as any).__inject__(this.$ssrContext)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
render () {
|
|
||||||
return <h1 class={styles.title}>Hello world!</h1>
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,3 +0,0 @@
|
|||||||
import HelloWorld from './HelloWorld'
|
|
||||||
|
|
||||||
export default HelloWorld
|
|
@ -1,4 +0,0 @@
|
|||||||
.title {
|
|
||||||
font-style: italic;
|
|
||||||
color: green;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
export const title: string;
|
|
@ -1,19 +0,0 @@
|
|||||||
import NuxtConfiguration from '@nuxt/config'
|
|
||||||
|
|
||||||
const config: NuxtConfiguration = {
|
|
||||||
build: {
|
|
||||||
loaders: {
|
|
||||||
vueStyle: {
|
|
||||||
manualInject: true
|
|
||||||
},
|
|
||||||
css: {
|
|
||||||
modules: {
|
|
||||||
localIdentName: '[local]_[hash:base64:5]'
|
|
||||||
},
|
|
||||||
importLoaders: 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "typescript-tsx",
|
|
||||||
"private": true,
|
|
||||||
"version": "1.0.0",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nuxt",
|
|
||||||
"build": "nuxt build",
|
|
||||||
"start": "nuxt start",
|
|
||||||
"generate": "nuxt generate",
|
|
||||||
"post-update": "yarn upgrade --latest",
|
|
||||||
"watch:css": "tcm components -w"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"nuxt": "latest",
|
|
||||||
"ts-node": "^8.1.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@nuxt/typescript": "latest",
|
|
||||||
"typed-css-modules": "^0.3.7"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import HelloWorld from '../components/HelloWorld'
|
|
||||||
|
|
||||||
export default Vue.extend({
|
|
||||||
name: 'Home',
|
|
||||||
render () {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<HelloWorld />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
11
examples/typescript-tsx/shims-tsx.d.ts
vendored
11
examples/typescript-tsx/shims-tsx.d.ts
vendored
@ -1,11 +0,0 @@
|
|||||||
import Vue, { VNode } from 'vue'
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace JSX {
|
|
||||||
interface Element extends VNode {}
|
|
||||||
interface ElementClass extends Vue {}
|
|
||||||
interface IntrinsicElements {
|
|
||||||
[elem: string]: any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"lib": [
|
|
||||||
"esnext",
|
|
||||||
"esnext.asynciterable",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"jsx": "preserve",
|
|
||||||
"sourceMap": true,
|
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noImplicitThis": true,
|
|
||||||
"noEmit": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"~/*": [
|
|
||||||
"./*"
|
|
||||||
],
|
|
||||||
"@/*": [
|
|
||||||
"./*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"types": [
|
|
||||||
"@types/node",
|
|
||||||
"@nuxt/vue-app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
# Nuxt with TypeScript and Vuex
|
|
||||||
|
|
||||||
https://nuxtjs.org/examples/typescript-vuex
|
|
File diff suppressed because one or more lines are too long
@ -1,28 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="ba b--black-20 mw5 ma2">
|
|
||||||
<img :src="'https://robots.johnlindquist.com/' + person.first_name + '_' + person.last_name">
|
|
||||||
<div class="flex flex-column items-center pa2 b--black-20">
|
|
||||||
<div class="f4">
|
|
||||||
{{ person.first_name }} {{ person.last_name }}
|
|
||||||
</div>
|
|
||||||
<button class="w-100 bg-blue dim mv2 pv2 bn pointer" @click="select(person.id)">
|
|
||||||
Select
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Vue, Component, Prop } from 'vue-property-decorator'
|
|
||||||
import { namespace } from 'vuex-class'
|
|
||||||
|
|
||||||
import * as people from '~/store/modules/people'
|
|
||||||
|
|
||||||
const People = namespace(people.name)
|
|
||||||
|
|
||||||
@Component
|
|
||||||
export default class Card extends Vue {
|
|
||||||
@Prop() person
|
|
||||||
@People.Action select
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,12 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="container">
|
|
||||||
<Nuxt />
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
|
|
||||||
@Component
|
|
||||||
export default class DefaultLayout extends Vue {}
|
|
||||||
</script>
|
|
@ -1,17 +0,0 @@
|
|||||||
import NuxtConfiguration from '@nuxt/config'
|
|
||||||
|
|
||||||
const config: NuxtConfiguration = {
|
|
||||||
head: {
|
|
||||||
title: 'starter',
|
|
||||||
meta: [
|
|
||||||
{ charset: 'utf-8' },
|
|
||||||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
||||||
{ hid: 'description', name: 'description', content: 'Nuxt TS project' }
|
|
||||||
],
|
|
||||||
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
|
||||||
},
|
|
||||||
loading: { color: '#3B8070' },
|
|
||||||
css: ['tachyons/css/tachyons.min.css', '~/assets/css/main.css']
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"axios": "^0.19.0",
|
|
||||||
"nuxt": "latest",
|
|
||||||
"tachyons": "^4.11.1",
|
|
||||||
"ts-node": "^8.1.0",
|
|
||||||
"vue-property-decorator": "^7.3.0",
|
|
||||||
"vuex-class": "^0.3.1"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nuxt",
|
|
||||||
"build": "nuxt build",
|
|
||||||
"start": "nuxt start",
|
|
||||||
"generate": "nuxt generate",
|
|
||||||
"post-update": "yarn upgrade --latest"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@nuxt/typescript": "latest"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
<template>
|
|
||||||
<section class="pa4">
|
|
||||||
<div class="bg-white-90 pa4">
|
|
||||||
<div class="f1">
|
|
||||||
Nuxt TypeScript Starter
|
|
||||||
</div>
|
|
||||||
<div class="f3">
|
|
||||||
Selected Person: {{ selectedPerson.first_name }} {{ selectedPerson.last_name }}
|
|
||||||
</div>
|
|
||||||
{{ selected }}
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-wrap ph2 justify-between bg-white-80">
|
|
||||||
<div v-for="person in people" :key="person.id">
|
|
||||||
<Card :person="person" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
import { namespace } from 'vuex-class'
|
|
||||||
import Card from '~/components/Card.vue'
|
|
||||||
|
|
||||||
import * as people from '~/store/modules/people'
|
|
||||||
|
|
||||||
const People = namespace(people.name)
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
components: {
|
|
||||||
Card
|
|
||||||
}
|
|
||||||
})
|
|
||||||
export default class IndexPage extends Vue {
|
|
||||||
@People.State selected
|
|
||||||
@People.State people
|
|
||||||
@People.Getter selectedPerson
|
|
||||||
}
|
|
||||||
</script>
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
|||||||
import Vuex from 'vuex'
|
|
||||||
import * as root from './root'
|
|
||||||
import * as people from './modules/people'
|
|
||||||
|
|
||||||
// More info about store: https://vuex.vuejs.org/en/core-concepts.html
|
|
||||||
// See https://nuxtjs.org/guide/vuex-store#classic-mode
|
|
||||||
// structure of the store:
|
|
||||||
// types: Types that represent the keys of the mutations to commit
|
|
||||||
// state: The information of our app, we can get or update it.
|
|
||||||
// getters: Get complex information from state
|
|
||||||
// action: Sync or async operations that commit mutations
|
|
||||||
// mutations: Modify the state
|
|
||||||
|
|
||||||
export type RootState = root.State
|
|
||||||
|
|
||||||
const createStore = () => {
|
|
||||||
return new Vuex.Store({
|
|
||||||
state: root.state(),
|
|
||||||
getters: root.getters,
|
|
||||||
mutations: root.mutations,
|
|
||||||
actions: root.actions,
|
|
||||||
modules: {
|
|
||||||
[people.name]: people
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export default createStore
|
|
@ -1,71 +0,0 @@
|
|||||||
import { ActionTree, MutationTree, GetterTree, ActionContext } from 'vuex'
|
|
||||||
import { RootState } from 'store'
|
|
||||||
|
|
||||||
export const name = 'people'
|
|
||||||
|
|
||||||
export const types = {
|
|
||||||
SELECT: 'SELECT',
|
|
||||||
SET: 'SET'
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PersonContact {
|
|
||||||
email: string
|
|
||||||
phone: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PersonAddress {
|
|
||||||
city: string
|
|
||||||
country: string
|
|
||||||
postalCode: string
|
|
||||||
state: string
|
|
||||||
street: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Person {
|
|
||||||
id: number
|
|
||||||
first_name: string
|
|
||||||
last_name: string
|
|
||||||
contact: PersonContact
|
|
||||||
gender: string
|
|
||||||
ip_address: string
|
|
||||||
avatar: string
|
|
||||||
address: PersonAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface State {
|
|
||||||
selected: number
|
|
||||||
people: Person[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const namespaced = true
|
|
||||||
|
|
||||||
export const state = (): State => ({
|
|
||||||
selected: 1,
|
|
||||||
people: []
|
|
||||||
})
|
|
||||||
|
|
||||||
export const getters: GetterTree<State, RootState> = {
|
|
||||||
selectedPerson: state => {
|
|
||||||
const p = state.people.find(person => person.id === state.selected)
|
|
||||||
return p ? p : { first_name: 'Please,', last_name: 'select someone' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Actions<S, R> extends ActionTree<S, R> {
|
|
||||||
select (context: ActionContext<S, R>, id: number): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export const actions: Actions<State, RootState> = {
|
|
||||||
select ({ commit }, id: number) {
|
|
||||||
commit(types.SELECT, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations: MutationTree<State> = {
|
|
||||||
[types.SELECT] (state, id: number) {
|
|
||||||
state.selected = id
|
|
||||||
},
|
|
||||||
[types.SET] (state, people: Person[]) {
|
|
||||||
state.people = people
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
import { GetterTree, ActionContext, ActionTree, MutationTree } from 'vuex'
|
|
||||||
import axios from 'axios'
|
|
||||||
import { RootState } from 'store'
|
|
||||||
import * as people from './modules/people'
|
|
||||||
|
|
||||||
export const types = {}
|
|
||||||
|
|
||||||
export interface State {}
|
|
||||||
|
|
||||||
export const state = (): State => ({})
|
|
||||||
|
|
||||||
export const getters: GetterTree<State, RootState> = {}
|
|
||||||
|
|
||||||
export interface Actions<S, R> extends ActionTree<S, R> {
|
|
||||||
nuxtServerInit (context: ActionContext<S, R>): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export const actions: Actions<State, RootState> = {
|
|
||||||
async nuxtServerInit ({ commit }) {
|
|
||||||
const response = await axios.get('/random-data.json', { proxy: { host: '127.0.0.1', port: 3000 } })
|
|
||||||
const staticPeople = response.data.slice(0, 10)
|
|
||||||
commit(`${people.name}/${people.types.SET}`, staticPeople, { root: true })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations: MutationTree<State> = {}
|
|
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"lib": [
|
|
||||||
"esnext",
|
|
||||||
"esnext.asynciterable",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noEmit": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"~/*": [
|
|
||||||
"./*"
|
|
||||||
],
|
|
||||||
"@/*": [
|
|
||||||
"./*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"types": [
|
|
||||||
"@types/node",
|
|
||||||
"@nuxt/vue-app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
# Nuxt with TypeScript example
|
|
||||||
|
|
||||||
https://codesandbox.io/s/0qmykr7wq0
|
|
@ -1,14 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
{{ message }}
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
|
|
||||||
@Component
|
|
||||||
export default class HelloWorld extends Vue {
|
|
||||||
message: string = 'Hello world !'
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,7 +0,0 @@
|
|||||||
import NuxtConfiguration from '@nuxt/config'
|
|
||||||
|
|
||||||
const config: NuxtConfiguration = {
|
|
||||||
plugins: ['~/plugins/hello']
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"nuxt": "latest",
|
|
||||||
"ts-node": "^8.1.0",
|
|
||||||
"vue-property-decorator": "^7.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nuxt",
|
|
||||||
"build": "nuxt build",
|
|
||||||
"start": "nuxt start",
|
|
||||||
"generate": "nuxt generate",
|
|
||||||
"post-update": "yarn upgrade --latest"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@nuxt/typescript": "latest"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
<template>
|
|
||||||
<HelloWorld />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
import HelloWorld from '~/components/HelloWorld.vue'
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
components: {
|
|
||||||
HelloWorld
|
|
||||||
}
|
|
||||||
})
|
|
||||||
export default class Home extends Vue {}
|
|
||||||
</script>
|
|
@ -1,3 +0,0 @@
|
|||||||
export default () => {
|
|
||||||
console.log(`Hello from ${process.server ? 'Server' : 'Client'} !`)
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"lib": [
|
|
||||||
"esnext",
|
|
||||||
"esnext.asynciterable",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noEmit": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"~/*": [
|
|
||||||
"./*"
|
|
||||||
],
|
|
||||||
"@/*": [
|
|
||||||
"./*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"types": [
|
|
||||||
"@types/node",
|
|
||||||
"@nuxt/vue-app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,13 +34,11 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
|
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts$': 'ts-jest',
|
|
||||||
'^.+\\.js$': 'babel-jest',
|
'^.+\\.js$': 'babel-jest',
|
||||||
'^.+\\.vue$': 'vue-jest'
|
'^.+\\.vue$': 'vue-jest'
|
||||||
},
|
},
|
||||||
|
|
||||||
moduleFileExtensions: [
|
moduleFileExtensions: [
|
||||||
'ts',
|
|
||||||
'js',
|
'js',
|
||||||
'json'
|
'json'
|
||||||
],
|
],
|
||||||
|
10
package.json
10
package.json
@ -23,11 +23,10 @@
|
|||||||
"lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
"lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
||||||
"nuxt": "node -r esm ./packages/cli/bin/nuxt-cli.js",
|
"nuxt": "node -r esm ./packages/cli/bin/nuxt-cli.js",
|
||||||
"pkg": "node -r esm ./scripts/package",
|
"pkg": "node -r esm ./scripts/package",
|
||||||
"test": "yarn test:fixtures && yarn test:unit && yarn test:types",
|
"test": "yarn test:fixtures && yarn test:unit",
|
||||||
"test:e2e": "jest -i test/e2e --forceExit",
|
"test:e2e": "jest -i test/e2e --forceExit",
|
||||||
"test:fixtures": "jest test/fixtures --forceExit",
|
"test:fixtures": "jest test/fixtures --forceExit",
|
||||||
"test:lint": "yarn lint",
|
"test:lint": "yarn lint",
|
||||||
"test:types": "tsc -p test/types",
|
|
||||||
"test:unit": "jest test/unit packages --forceExit"
|
"test:unit": "jest test/unit packages --forceExit"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -74,11 +73,6 @@
|
|||||||
"rollup-plugin-node-resolve": "^5.2.0",
|
"rollup-plugin-node-resolve": "^5.2.0",
|
||||||
"rollup-plugin-replace": "^2.2.0",
|
"rollup-plugin-replace": "^2.2.0",
|
||||||
"sort-package-json": "^1.22.1",
|
"sort-package-json": "^1.22.1",
|
||||||
"ts-jest": "^24.0.2",
|
"vue-jest": "^4.0.0-beta.2"
|
||||||
"ts-node": "^8.3.0",
|
|
||||||
"tslint": "^5.18.0",
|
|
||||||
"typescript": "^3.5.3",
|
|
||||||
"vue-jest": "^4.0.0-beta.2",
|
|
||||||
"vue-property-decorator": "^8.2.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ export default class Builder {
|
|||||||
restart: null
|
restart: null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.supportedExtensions = ['vue', 'js', 'ts', 'tsx', ...(this.options.build.additionalExtensions || [])]
|
this.supportedExtensions = ['vue', 'js', ...(this.options.build.additionalExtensions || [])]
|
||||||
|
|
||||||
// Helper to resolve build paths
|
// Helper to resolve build paths
|
||||||
this.relativeToBuild = (...args) => relativeTo(this.options.buildDir, ...args)
|
this.relativeToBuild = (...args) => relativeTo(this.options.buildDir, ...args)
|
||||||
|
@ -32,7 +32,7 @@ describe('builder: builder constructor', () => {
|
|||||||
custom: null,
|
custom: null,
|
||||||
restart: null
|
restart: null
|
||||||
})
|
})
|
||||||
expect(builder.supportedExtensions).toEqual(['vue', 'js', 'ts', 'tsx'])
|
expect(builder.supportedExtensions).toEqual(['vue', 'js'])
|
||||||
expect(builder.relativeToBuild).toBeInstanceOf(Function)
|
expect(builder.relativeToBuild).toBeInstanceOf(Function)
|
||||||
|
|
||||||
expect(builder._buildStatus).toEqual(1)
|
expect(builder._buildStatus).toEqual(1)
|
||||||
|
@ -76,7 +76,7 @@ describe('builder: builder generate', () => {
|
|||||||
])
|
])
|
||||||
expect(builder.resolveCustomTemplates).toBeCalledTimes(1)
|
expect(builder.resolveCustomTemplates).toBeCalledTimes(1)
|
||||||
expect(builder.resolveLoadingIndicator).toBeCalledTimes(1)
|
expect(builder.resolveLoadingIndicator).toBeCalledTimes(1)
|
||||||
expect(builder.options.build.watch).toEqual(['/var/nuxt/src/template/**/*.{vue,js,ts,tsx}'])
|
expect(builder.options.build.watch).toEqual(['/var/nuxt/src/template/**/*.{vue,js}'])
|
||||||
expect(builder.compileTemplates).toBeCalledTimes(1)
|
expect(builder.compileTemplates).toBeCalledTimes(1)
|
||||||
expect(consola.success).toBeCalledTimes(1)
|
expect(consola.success).toBeCalledTimes(1)
|
||||||
expect(consola.success).toBeCalledWith('Nuxt files generated')
|
expect(consola.success).toBeCalledWith('Nuxt files generated')
|
||||||
@ -95,7 +95,7 @@ describe('builder: builder generate', () => {
|
|||||||
|
|
||||||
expect(Glob).toBeCalledTimes(1)
|
expect(Glob).toBeCalledTimes(1)
|
||||||
expect(Glob).toBeCalledWith(
|
expect(Glob).toBeCalledWith(
|
||||||
'/var/nuxt/dir/**/*.{vue,js,ts,tsx}',
|
'/var/nuxt/dir/**/*.{vue,js}',
|
||||||
{ cwd: '/var/nuxt/src', ignore: '/var/nuxt/ignore' }
|
{ cwd: '/var/nuxt/src', ignore: '/var/nuxt/ignore' }
|
||||||
)
|
)
|
||||||
expect(builder.ignore.filter).toBeCalledTimes(1)
|
expect(builder.ignore.filter).toBeCalledTimes(1)
|
||||||
@ -624,7 +624,7 @@ describe('builder: builder generate', () => {
|
|||||||
srcDir: '/var/nuxt/src',
|
srcDir: '/var/nuxt/src',
|
||||||
pagesDir: '/var/nuxt/pages',
|
pagesDir: '/var/nuxt/pages',
|
||||||
routeNameSplitter: '[splitter]',
|
routeNameSplitter: '[splitter]',
|
||||||
supportedExtensions: ['vue', 'js', 'ts', 'tsx']
|
supportedExtensions: ['vue', 'js']
|
||||||
})
|
})
|
||||||
expect(nuxt.callHook).toBeCalledTimes(1)
|
expect(nuxt.callHook).toBeCalledTimes(1)
|
||||||
expect(nuxt.callHook).toBeCalledWith(
|
expect(nuxt.callHook).toBeCalledWith(
|
||||||
|
@ -117,7 +117,7 @@ describe('builder: builder plugins', () => {
|
|||||||
]
|
]
|
||||||
builder.relativeToBuild = jest.fn(src => `relative(${src})`)
|
builder.relativeToBuild = jest.fn(src => `relative(${src})`)
|
||||||
|
|
||||||
Glob.mockImplementationOnce(src => [`${src}.js`, `${src}.ts`])
|
Glob.mockImplementationOnce(src => [`${src}.js`])
|
||||||
isIndexFileAndFolder.mockReturnValueOnce(false)
|
isIndexFileAndFolder.mockReturnValueOnce(false)
|
||||||
|
|
||||||
await builder.resolvePlugins()
|
await builder.resolvePlugins()
|
||||||
|
@ -46,8 +46,8 @@ describe('builder: builder watch', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const globbedPatterns = [
|
const globbedPatterns = [
|
||||||
'/var/nuxt/src/layouts/**/*.{vue,js,ts,tsx}',
|
'/var/nuxt/src/layouts/**/*.{vue,js}',
|
||||||
'/var/nuxt/src/middleware/**/*.{vue,js,ts,tsx}'
|
'/var/nuxt/src/middleware/**/*.{vue,js}'
|
||||||
]
|
]
|
||||||
|
|
||||||
expect(r).toBeCalledTimes(2)
|
expect(r).toBeCalledTimes(2)
|
||||||
@ -133,7 +133,7 @@ describe('builder: builder watch', () => {
|
|||||||
expect(r).nthCalledWith(3, '/var/nuxt/src', '/var/nuxt/src/pages')
|
expect(r).nthCalledWith(3, '/var/nuxt/src', '/var/nuxt/src/pages')
|
||||||
|
|
||||||
expect(upath.normalizeSafe).toBeCalledTimes(3)
|
expect(upath.normalizeSafe).toBeCalledTimes(3)
|
||||||
expect(upath.normalizeSafe).nthCalledWith(3, '/var/nuxt/src/pages/**/*.{vue,js,ts,tsx}', 2, expect.any(Array))
|
expect(upath.normalizeSafe).nthCalledWith(3, '/var/nuxt/src/pages/**/*.{vue,js}', 2, expect.any(Array))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should invoke generateRoutesAndFiles on file refresh', () => {
|
test('should invoke generateRoutesAndFiles on file refresh', () => {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
import path from 'path'
|
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import minimist from 'minimist'
|
import minimist from 'minimist'
|
||||||
import { name, version } from '../package.json'
|
import { name, version } from '../package.json'
|
||||||
@ -7,7 +6,6 @@ import { forceExit } from './utils'
|
|||||||
import { loadNuxtConfig } from './utils/config'
|
import { loadNuxtConfig } from './utils/config'
|
||||||
import { indent, foldLines, colorize } from './utils/formatting'
|
import { indent, foldLines, colorize } from './utils/formatting'
|
||||||
import { startSpaces, optionSpaces, forceExitTimeout } from './utils/constants'
|
import { startSpaces, optionSpaces, forceExitTimeout } from './utils/constants'
|
||||||
import { detectTypeScript } from './utils/typescript'
|
|
||||||
import * as imports from './imports'
|
import * as imports from './imports'
|
||||||
|
|
||||||
export default class NuxtCommand {
|
export default class NuxtCommand {
|
||||||
@ -92,16 +90,9 @@ export default class NuxtCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getNuxtConfig (extraOptions = {}) {
|
async getNuxtConfig (extraOptions = {}) {
|
||||||
const rootDir = path.resolve(this.argv._[0] || '.')
|
|
||||||
|
|
||||||
// Flag to indicate nuxt is running with CLI (not programmatic)
|
// Flag to indicate nuxt is running with CLI (not programmatic)
|
||||||
extraOptions._cli = true
|
extraOptions._cli = true
|
||||||
|
|
||||||
// Typescript support
|
|
||||||
extraOptions._typescript = await detectTypeScript(rootDir, {
|
|
||||||
transpileOnly: this.cmd.name === 'start'
|
|
||||||
})
|
|
||||||
|
|
||||||
const config = await loadNuxtConfig(this.argv)
|
const config = await loadNuxtConfig(this.argv)
|
||||||
const options = Object.assign(config, extraOptions)
|
const options = Object.assign(config, extraOptions)
|
||||||
|
|
||||||
|
@ -27,7 +27,4 @@ export const webpack = () => _import('@nuxt/webpack')
|
|||||||
export const generator = () => _import('@nuxt/generator')
|
export const generator = () => _import('@nuxt/generator')
|
||||||
export const core = () => _import('@nuxt/core')
|
export const core = () => _import('@nuxt/core')
|
||||||
|
|
||||||
export const tsNode = () => _import('ts-node')
|
|
||||||
export const nuxtTypescript = () => _import('@nuxt/typescript')
|
|
||||||
|
|
||||||
export const importModule = _import
|
export const importModule = _import
|
||||||
|
@ -25,10 +25,6 @@ export function showBanner (nuxt, showMemoryUsage = true) {
|
|||||||
// Running mode
|
// Running mode
|
||||||
titleLines.push(`Running in ${nuxt.options.dev ? chalk.bold.blue('development') : chalk.bold.green('production')} mode (${chalk.bold(nuxt.options.mode)})`)
|
titleLines.push(`Running in ${nuxt.options.dev ? chalk.bold.blue('development') : chalk.bold.green('production')} mode (${chalk.bold(nuxt.options.mode)})`)
|
||||||
|
|
||||||
if (nuxt.options._typescript && nuxt.options._typescript.runtime) {
|
|
||||||
titleLines.push(`TypeScript support is ${chalk.green.bold('enabled')}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showMemoryUsage) {
|
if (showMemoryUsage) {
|
||||||
titleLines.push(getFormattedMemoryUsage())
|
titleLines.push(getFormattedMemoryUsage())
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,7 @@ export async function loadNuxtConfig (argv) {
|
|||||||
// Clear cache
|
// Clear cache
|
||||||
clearRequireCache(nuxtConfigFile)
|
clearRequireCache(nuxtConfigFile)
|
||||||
|
|
||||||
if (nuxtConfigFile.endsWith('.ts')) {
|
options = esm(module)(nuxtConfigFile) || {}
|
||||||
options = require(nuxtConfigFile) || {}
|
|
||||||
} else {
|
|
||||||
options = esm(module)(nuxtConfigFile) || {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.default) {
|
if (options.default) {
|
||||||
options = options.default
|
options = options.default
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
import path from 'path'
|
|
||||||
import fs from 'fs-extra'
|
|
||||||
import * as imports from '../imports'
|
|
||||||
|
|
||||||
let _guard = false
|
|
||||||
export const setGuard = (val) => { _guard = val }
|
|
||||||
|
|
||||||
async function registerTSNode ({ tsConfigPath, options }) {
|
|
||||||
if (_guard) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { register } = await imports.tsNode()
|
|
||||||
|
|
||||||
// https://github.com/TypeStrong/ts-node
|
|
||||||
register({
|
|
||||||
project: tsConfigPath,
|
|
||||||
compilerOptions: {
|
|
||||||
module: 'commonjs'
|
|
||||||
},
|
|
||||||
...options
|
|
||||||
})
|
|
||||||
|
|
||||||
_guard = true
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getNuxtTypeScript () {
|
|
||||||
try {
|
|
||||||
return await imports.nuxtTypescript()
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
||||||
throw (error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function detectTypeScript (rootDir, options = {}) {
|
|
||||||
const typescript = {
|
|
||||||
tsConfigPath: path.resolve(rootDir, 'tsconfig.json'),
|
|
||||||
tsConfigExists: false,
|
|
||||||
runtime: false,
|
|
||||||
build: false,
|
|
||||||
options
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if tsconfig.json exists
|
|
||||||
typescript.tsConfigExists = await fs.exists(typescript.tsConfigPath)
|
|
||||||
|
|
||||||
// Skip if tsconfig.json not exists
|
|
||||||
if (!typescript.tsConfigExists) {
|
|
||||||
return typescript
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register runtime support
|
|
||||||
typescript.runtime = true
|
|
||||||
await registerTSNode(typescript)
|
|
||||||
|
|
||||||
// Try to load @nuxt/typescript
|
|
||||||
const nuxtTypeScript = await getNuxtTypeScript()
|
|
||||||
|
|
||||||
// If exists do additional setup
|
|
||||||
if (nuxtTypeScript) {
|
|
||||||
typescript.build = true
|
|
||||||
await nuxtTypeScript.setupDefaults(typescript.tsConfigPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return typescript
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
import { resolve } from 'path'
|
|
||||||
import { mkdirp, writeFile, remove } from 'fs-extra'
|
|
||||||
import { register } from 'ts-node'
|
|
||||||
import { detectTypeScript, setGuard } from '../../src/utils/typescript'
|
|
||||||
|
|
||||||
jest.mock('ts-node')
|
|
||||||
|
|
||||||
describe('Typescript Support', () => {
|
|
||||||
const rootDir = 'tmp'
|
|
||||||
const rootDir2 = 'tmp2'
|
|
||||||
const tsConfigPath = resolve(rootDir, 'tsconfig.json')
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await mkdirp(rootDir)
|
|
||||||
await mkdirp(rootDir2)
|
|
||||||
await writeFile(tsConfigPath, '{}', 'utf-8')
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
register.mockReset()
|
|
||||||
setGuard(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detectTypeScript detects and registers runtime', async () => {
|
|
||||||
await detectTypeScript(rootDir)
|
|
||||||
expect(register).toHaveBeenCalledTimes(1)
|
|
||||||
expect(register).toHaveBeenCalledWith({
|
|
||||||
project: tsConfigPath,
|
|
||||||
compilerOptions: {
|
|
||||||
module: 'commonjs'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('multiple detectTypeScript calls registers runtime only once', async () => {
|
|
||||||
await detectTypeScript(rootDir)
|
|
||||||
await detectTypeScript(rootDir)
|
|
||||||
expect(register).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detectTypeScript skips rootDir without tsconfig.json', async () => {
|
|
||||||
await detectTypeScript(rootDir2)
|
|
||||||
expect(register).toHaveBeenCalledTimes(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await remove(rootDir)
|
|
||||||
await remove(rootDir2)
|
|
||||||
})
|
|
||||||
})
|
|
@ -4,11 +4,9 @@
|
|||||||
"repository": "nuxt/nuxt.js",
|
"repository": "nuxt/nuxt.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist"
|
||||||
"types/*.d.ts"
|
|
||||||
],
|
],
|
||||||
"main": "dist/config.js",
|
"main": "dist/config.js",
|
||||||
"typings": "types/index.d.ts",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/utils": "2.8.1",
|
"@nuxt/utils": "2.8.1",
|
||||||
"consola": "^2.9.0",
|
"consola": "^2.9.0",
|
||||||
|
@ -51,20 +51,8 @@ export default () => ({
|
|||||||
},
|
},
|
||||||
scss: {},
|
scss: {},
|
||||||
stylus: {},
|
stylus: {},
|
||||||
ts: {
|
|
||||||
transpileOnly: true,
|
|
||||||
appendTsSuffixTo: [/\.vue$/]
|
|
||||||
},
|
|
||||||
tsx: {
|
|
||||||
transpileOnly: true,
|
|
||||||
appendTsxSuffixTo: [/\.vue$/]
|
|
||||||
},
|
|
||||||
vueStyle: {}
|
vueStyle: {}
|
||||||
},
|
},
|
||||||
typescript: {
|
|
||||||
typeCheck: true,
|
|
||||||
ignoreNotFoundWarnings: false
|
|
||||||
},
|
|
||||||
styleResources: {},
|
styleResources: {},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
terser: {},
|
terser: {},
|
||||||
|
@ -153,7 +153,7 @@ export function getNuxtConfig (_options) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const mandatoryExtensions = ['js', 'mjs', 'ts']
|
const mandatoryExtensions = ['js', 'mjs']
|
||||||
|
|
||||||
options.extensions = mandatoryExtensions
|
options.extensions = mandatoryExtensions
|
||||||
.filter(ext => !options.extensions.includes(ext))
|
.filter(ext => !options.extensions.includes(ext))
|
||||||
|
@ -91,18 +91,6 @@ Object {
|
|||||||
"stylus": Object {
|
"stylus": Object {
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
},
|
},
|
||||||
"ts": Object {
|
|
||||||
"appendTsSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"tsx": Object {
|
|
||||||
"appendTsxSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"vue": Object {
|
"vue": Object {
|
||||||
"productionMode": true,
|
"productionMode": true,
|
||||||
"transformAssetUrls": Object {
|
"transformAssetUrls": Object {
|
||||||
@ -151,10 +139,6 @@ Object {
|
|||||||
"templates": Array [],
|
"templates": Array [],
|
||||||
"terser": Object {},
|
"terser": Object {},
|
||||||
"transpile": Array [],
|
"transpile": Array [],
|
||||||
"typescript": Object {
|
|
||||||
"ignoreNotFoundWarnings": false,
|
|
||||||
"typeCheck": true,
|
|
||||||
},
|
|
||||||
"warningIgnoreFilters": Array [],
|
"warningIgnoreFilters": Array [],
|
||||||
"watch": Array [],
|
"watch": Array [],
|
||||||
},
|
},
|
||||||
@ -179,7 +163,6 @@ Object {
|
|||||||
"extensions": Array [
|
"extensions": Array [
|
||||||
"js",
|
"js",
|
||||||
"mjs",
|
"mjs",
|
||||||
"ts",
|
|
||||||
],
|
],
|
||||||
"fetch": Object {
|
"fetch": Object {
|
||||||
"client": true,
|
"client": true,
|
||||||
|
@ -68,18 +68,6 @@ Object {
|
|||||||
},
|
},
|
||||||
"scss": Object {},
|
"scss": Object {},
|
||||||
"stylus": Object {},
|
"stylus": Object {},
|
||||||
"ts": Object {
|
|
||||||
"appendTsSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"tsx": Object {
|
|
||||||
"appendTsxSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"vue": Object {
|
"vue": Object {
|
||||||
"transformAssetUrls": Object {
|
"transformAssetUrls": Object {
|
||||||
"embed": "src",
|
"embed": "src",
|
||||||
@ -131,10 +119,6 @@ Object {
|
|||||||
"templates": Array [],
|
"templates": Array [],
|
||||||
"terser": Object {},
|
"terser": Object {},
|
||||||
"transpile": Array [],
|
"transpile": Array [],
|
||||||
"typescript": Object {
|
|
||||||
"ignoreNotFoundWarnings": false,
|
|
||||||
"typeCheck": true,
|
|
||||||
},
|
|
||||||
"warningIgnoreFilters": Array [],
|
"warningIgnoreFilters": Array [],
|
||||||
"watch": Array [],
|
"watch": Array [],
|
||||||
},
|
},
|
||||||
@ -410,18 +394,6 @@ Object {
|
|||||||
},
|
},
|
||||||
"scss": Object {},
|
"scss": Object {},
|
||||||
"stylus": Object {},
|
"stylus": Object {},
|
||||||
"ts": Object {
|
|
||||||
"appendTsSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"tsx": Object {
|
|
||||||
"appendTsxSuffixTo": Array [
|
|
||||||
/\\\\\\.vue\\$/,
|
|
||||||
],
|
|
||||||
"transpileOnly": true,
|
|
||||||
},
|
|
||||||
"vue": Object {
|
"vue": Object {
|
||||||
"transformAssetUrls": Object {
|
"transformAssetUrls": Object {
|
||||||
"embed": "src",
|
"embed": "src",
|
||||||
@ -473,10 +445,6 @@ Object {
|
|||||||
"templates": Array [],
|
"templates": Array [],
|
||||||
"terser": Object {},
|
"terser": Object {},
|
||||||
"transpile": Array [],
|
"transpile": Array [],
|
||||||
"typescript": Object {
|
|
||||||
"ignoreNotFoundWarnings": false,
|
|
||||||
"typeCheck": true,
|
|
||||||
},
|
|
||||||
"warningIgnoreFilters": Array [],
|
"warningIgnoreFilters": Array [],
|
||||||
"watch": Array [],
|
"watch": Array [],
|
||||||
},
|
},
|
||||||
|
@ -74,7 +74,7 @@ describe('config: options', () => {
|
|||||||
|
|
||||||
test('should transform extensions to array', () => {
|
test('should transform extensions to array', () => {
|
||||||
const { extensions } = getNuxtConfig({ extensions: 'ext' })
|
const { extensions } = getNuxtConfig({ extensions: 'ext' })
|
||||||
expect(extensions).toEqual(['js', 'mjs', 'ts', 'ext'])
|
expect(extensions).toEqual(['js', 'mjs', 'ext'])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should support custom global name', () => {
|
test('should support custom global name', () => {
|
||||||
|
81
packages/config/types/build.d.ts
vendored
81
packages/config/types/build.d.ts
vendored
@ -1,81 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationBuild
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-build
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
Configuration as WebpackConfiguration,
|
|
||||||
Options as WebpackOptions,
|
|
||||||
Plugin as WebpackPlugin
|
|
||||||
} from 'webpack'
|
|
||||||
import { TransformOptions, PluginItem } from '@babel/core'
|
|
||||||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
||||||
import { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
|
||||||
import { Options as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware'
|
|
||||||
import { Options as HtmlMinifierOptions } from 'html-minifier'
|
|
||||||
import { Options as OptimizeCssAssetsWebpackPluginOptions } from 'optimize-css-assets-webpack-plugin'
|
|
||||||
import { TerserPluginOptions } from 'terser-webpack-plugin'
|
|
||||||
|
|
||||||
type NuxtConfigurationLoaders = any // TBD
|
|
||||||
|
|
||||||
interface NuxtBabelPresetEnv {
|
|
||||||
isServer: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NuxtBabelOptions extends Pick<TransformOptions, Exclude<keyof TransformOptions, 'presets'>> {
|
|
||||||
cacheCompression?: boolean
|
|
||||||
cacheDirectory?: boolean
|
|
||||||
cacheIdentifier?: string
|
|
||||||
customize?: string | null
|
|
||||||
presets?: ((env: NuxtBabelPresetEnv, defaultPreset: [string, object]) => PluginItem[] | void) | PluginItem[] | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtConfigurationBuild {
|
|
||||||
analyze?: BundleAnalyzerPlugin.Options | boolean
|
|
||||||
babel?: NuxtBabelOptions
|
|
||||||
cache?: boolean
|
|
||||||
crossorigin?: string
|
|
||||||
cssSourceMap?: boolean
|
|
||||||
devMiddleware?: WebpackDevMiddlewareOptions
|
|
||||||
devtools?: boolean
|
|
||||||
extend?(
|
|
||||||
config: WebpackConfiguration,
|
|
||||||
ctx: {
|
|
||||||
isDev: boolean,
|
|
||||||
isClient: boolean,
|
|
||||||
isServer: boolean,
|
|
||||||
loaders: NuxtConfigurationLoaders
|
|
||||||
}
|
|
||||||
): void
|
|
||||||
extractCSS?: boolean
|
|
||||||
filenames?: { [key in 'app' | 'chunk' | 'css' | 'img' | 'font' | 'video']?: (ctx: { isDev: boolean }) => string }
|
|
||||||
friendlyErrors?: boolean
|
|
||||||
hardSource?: boolean
|
|
||||||
hotMiddleware?: WebpackHotMiddlewareOptions
|
|
||||||
html?: { minify: HtmlMinifierOptions }
|
|
||||||
indicator?: boolean
|
|
||||||
loaders?: NuxtConfigurationLoaders
|
|
||||||
optimization?: WebpackOptions.Optimization
|
|
||||||
optimizeCSS?: OptimizeCssAssetsWebpackPluginOptions | boolean
|
|
||||||
parallel?: boolean
|
|
||||||
plugins?: WebpackPlugin[]
|
|
||||||
postcss?: any // TBD
|
|
||||||
profile?: boolean
|
|
||||||
publicPath?: string
|
|
||||||
quiet?: boolean
|
|
||||||
splitChunks?: {
|
|
||||||
commons?: boolean
|
|
||||||
layouts?: boolean
|
|
||||||
pages?: boolean
|
|
||||||
}
|
|
||||||
ssr?: boolean
|
|
||||||
standalone?: boolean
|
|
||||||
templates?: any
|
|
||||||
terser?: TerserPluginOptions | boolean
|
|
||||||
transpile?: (string | RegExp)[]
|
|
||||||
typescript?: {
|
|
||||||
typeCheck?: { [key: string]: any } | boolean, // TBD - Couldn't find typedefs for the forkTsCheckerWebpackPlugin options
|
|
||||||
ignoreNotFoundWarnings?: boolean
|
|
||||||
}
|
|
||||||
watch?: string[]
|
|
||||||
}
|
|
6
packages/config/types/env.d.ts
vendored
6
packages/config/types/env.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationEnv
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-env
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type NuxtConfigurationEnv = { [key: string]: string }
|
|
9
packages/config/types/fetch.d.ts
vendored
9
packages/config/types/fetch.d.ts
vendored
@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationFetch
|
|
||||||
* Documentation: ?
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface NuxtConfigurationFetch {
|
|
||||||
client?: boolean
|
|
||||||
server?: boolean
|
|
||||||
}
|
|
19
packages/config/types/generate.d.ts
vendored
19
packages/config/types/generate.d.ts
vendored
@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationGenerate
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-generate
|
|
||||||
*/
|
|
||||||
|
|
||||||
type NuxtConfigurationGenerateRoute = string | { route: string, payload: any }
|
|
||||||
|
|
||||||
type NuxtConfigurationGenerateRoutesFunction = () => (Promise<NuxtConfigurationGenerateRoute[]> | NuxtConfigurationGenerateRoute[])
|
|
||||||
type NuxtConfigurationGenerateRoutesFunctionWithCallback = (callback: (err: Error, routes: NuxtConfigurationGenerateRoute[]) => void) => void
|
|
||||||
|
|
||||||
export interface NuxtConfigurationGenerate {
|
|
||||||
concurrency?: number
|
|
||||||
devtools?: boolean
|
|
||||||
dir?: string
|
|
||||||
fallback?: string | boolean
|
|
||||||
interval?: number
|
|
||||||
routes?: NuxtConfigurationGenerateRoute[] | NuxtConfigurationGenerateRoutesFunction | NuxtConfigurationGenerateRoutesFunctionWithCallback
|
|
||||||
subFolders?: boolean
|
|
||||||
}
|
|
7
packages/config/types/globals.d.ts
vendored
7
packages/config/types/globals.d.ts
vendored
@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationGlobals
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-globals
|
|
||||||
*/
|
|
||||||
|
|
||||||
type NuxtConfigurationCustomizableGlobalName = 'id' | 'nuxt' | 'context' | 'pluginPrefix' | 'readyCallback' | 'loadedCallback'
|
|
||||||
export type NuxtConfigurationGlobals = { [key in NuxtConfigurationCustomizableGlobalName]?: (globalName: string) => string }
|
|
9
packages/config/types/head.d.ts
vendored
9
packages/config/types/head.d.ts
vendored
@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationHead
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-head
|
|
||||||
* https://github.com/declandewet/vue-meta#recognized-metainfo-properties
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { MetaInfo } from 'vue-meta'
|
|
||||||
|
|
||||||
export type NuxtConfigurationHead = MetaInfo
|
|
50
packages/config/types/hooks.d.ts
vendored
50
packages/config/types/hooks.d.ts
vendored
@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationHooks
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-hooks
|
|
||||||
* https://nuxtjs.org/api/internals-nuxt#hooks
|
|
||||||
* https://nuxtjs.org/api/internals-renderer#hooks
|
|
||||||
* https://nuxtjs.org/api/internals-module-container#hooks
|
|
||||||
* https://nuxtjs.org/api/internals-builder#hooks
|
|
||||||
* https://nuxtjs.org/api/internals-generator#hooks
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface NuxtConfigurationHooks {
|
|
||||||
build?: {
|
|
||||||
before?(builder: any, buildOptions: any): void
|
|
||||||
compile?(params: { name: 'client' | 'server', compiler: any }): void
|
|
||||||
compiled?(params: { name: 'client' | 'server', compiler: any, stats: any }): void
|
|
||||||
done?(builder: any): void
|
|
||||||
extendRoutes?(routes: any, resolve: any): void
|
|
||||||
templates?(params: { templateFiles: any, templateVars: any, resolve: any }): void
|
|
||||||
}
|
|
||||||
close?(nuxt: any): void
|
|
||||||
error?(error: Error): void
|
|
||||||
generate?: {
|
|
||||||
before?(generator: any, generateOptions: any): void
|
|
||||||
distCopied?(generator: any): void
|
|
||||||
distRemoved?(generator: any): void
|
|
||||||
done?(generator: any): void
|
|
||||||
extendRoutes?(routes: any): void
|
|
||||||
page?(params: { route: any, path: any, html: any }): void
|
|
||||||
routeCreated?(route: any, path: any, errors: any): void
|
|
||||||
routeFailed?(route: any, errors: any): void
|
|
||||||
}
|
|
||||||
listen?(server: any, params: { host: string, port: number | string }): void
|
|
||||||
modules?: {
|
|
||||||
before?(moduleContainer: any, options: any): void
|
|
||||||
done?(moduleContainer: any): void
|
|
||||||
}
|
|
||||||
ready?(nuxt: any): void
|
|
||||||
render?: {
|
|
||||||
before?(renderer: any, options: any): void
|
|
||||||
done?(renderer: any): void
|
|
||||||
errorMiddleware?(app: any): void
|
|
||||||
resourcesLoaded?(resources: any): void
|
|
||||||
route?(url: string, result: any, context: any): void
|
|
||||||
routeContext?(context: any): void
|
|
||||||
routeDone?(url: string, result: any, context: any): void
|
|
||||||
setupMiddleware?(app: any): void
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hooks need too many core typedefs to be 100% defined
|
|
94
packages/config/types/index.d.ts
vendored
94
packages/config/types/index.d.ts
vendored
@ -1,94 +0,0 @@
|
|||||||
import { NuxtConfigurationBuild } from './build'
|
|
||||||
import { NuxtConfigurationEnv } from './env'
|
|
||||||
import { NuxtConfigurationFetch } from './fetch'
|
|
||||||
import { NuxtConfigurationGenerate } from './generate'
|
|
||||||
import { NuxtConfigurationHead } from './head'
|
|
||||||
import { NuxtConfigurationHooks } from './hooks'
|
|
||||||
import { NuxtConfigurationGlobals } from './globals'
|
|
||||||
import { NuxtConfigurationLoading, NuxtConfigurationLoadingIndicator } from './loading'
|
|
||||||
import { NuxtConfigurationModule } from './module'
|
|
||||||
import { NuxtConfigurationPlugin } from './plugin'
|
|
||||||
import { NuxtConfigurationRender } from './render'
|
|
||||||
import { NuxtConfigurationRouter, NuxtRouteConfig } from './router'
|
|
||||||
import { NuxtConfigurationServer } from './server'
|
|
||||||
import { NuxtConfigurationServerMiddleware } from './server-middleware'
|
|
||||||
import { NuxtConfigurationVueConfiguration } from './vue-configuration'
|
|
||||||
import { NuxtConfigurationWatchers } from './watchers'
|
|
||||||
|
|
||||||
type ExtendableConfiguration = { [key: string]: any }
|
|
||||||
|
|
||||||
export default interface NuxtConfiguration extends ExtendableConfiguration {
|
|
||||||
build?: NuxtConfigurationBuild
|
|
||||||
buildDir?: string
|
|
||||||
css?: string[]
|
|
||||||
dev?: boolean
|
|
||||||
env?: NuxtConfigurationEnv
|
|
||||||
fetch?: NuxtConfigurationFetch
|
|
||||||
generate?: NuxtConfigurationGenerate
|
|
||||||
globalName?: string
|
|
||||||
globals?: NuxtConfigurationGlobals
|
|
||||||
head?: NuxtConfigurationHead
|
|
||||||
hooks?: NuxtConfigurationHooks
|
|
||||||
ignorePrefix?: string
|
|
||||||
ignore?: string[]
|
|
||||||
layoutTransition?: any // TBD - should be of type `Transition` already defined in @nuxt/vue-app
|
|
||||||
loading?: NuxtConfigurationLoading | false | string
|
|
||||||
loadingIndicator?: NuxtConfigurationLoadingIndicator | false | string
|
|
||||||
mode?: 'spa' | 'universal' // TBR (To Be Reviewed) - should be a `NuxtMode` interface which should be used in @nuxt/vue-app/types/process.d.ts as well
|
|
||||||
modern?: 'client' | 'server' | boolean
|
|
||||||
modules?: NuxtConfigurationModule[]
|
|
||||||
devModules?: NuxtConfigurationModule[]
|
|
||||||
modulesDir?: string[]
|
|
||||||
plugins?: NuxtConfigurationPlugin[]
|
|
||||||
render?: NuxtConfigurationRender
|
|
||||||
rootDir?: string
|
|
||||||
router?: NuxtConfigurationRouter
|
|
||||||
server?: NuxtConfigurationServer
|
|
||||||
serverMiddleware?: NuxtConfigurationServerMiddleware[]
|
|
||||||
srcDir?: string
|
|
||||||
transition?: any // TBD - should be of type `Transition` already defined in @nuxt/vue-app
|
|
||||||
'vue.config'?: NuxtConfigurationVueConfiguration
|
|
||||||
watch?: string[]
|
|
||||||
watchers?: NuxtConfigurationWatchers
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
NuxtConfigurationBuild as Build,
|
|
||||||
NuxtConfigurationEnv as Env,
|
|
||||||
NuxtConfigurationFetch as Fetch,
|
|
||||||
NuxtConfigurationGenerate as Generate,
|
|
||||||
NuxtConfigurationHead as Head,
|
|
||||||
NuxtConfigurationHooks as Hooks,
|
|
||||||
NuxtConfigurationGlobals as Globals,
|
|
||||||
NuxtConfigurationLoading as Loading,
|
|
||||||
NuxtConfigurationLoadingIndicator as LoadingIndicator,
|
|
||||||
NuxtConfigurationModule as Module,
|
|
||||||
NuxtConfigurationPlugin as Plugin,
|
|
||||||
NuxtConfigurationRender as Render,
|
|
||||||
NuxtConfigurationRouter as Router,
|
|
||||||
NuxtRouteConfig as RouteConfig,
|
|
||||||
NuxtConfigurationServer as Server,
|
|
||||||
NuxtConfigurationServerMiddleware as ServerMiddleware,
|
|
||||||
NuxtConfigurationVueConfiguration as VueConfiguration,
|
|
||||||
NuxtConfigurationWatchers as Watchers
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace NuxtConfiguration {
|
|
||||||
export type Build = NuxtConfigurationBuild
|
|
||||||
export type Env = NuxtConfigurationEnv
|
|
||||||
export type Fetch = NuxtConfigurationFetch
|
|
||||||
export type Generate = NuxtConfigurationGenerate
|
|
||||||
export type Head = NuxtConfigurationHead
|
|
||||||
export type Hooks = NuxtConfigurationHooks
|
|
||||||
export type Globals = NuxtConfigurationGlobals
|
|
||||||
export type Loading = NuxtConfigurationLoading
|
|
||||||
export type LoadingIndicator = NuxtConfigurationLoadingIndicator
|
|
||||||
export type Module = NuxtConfigurationModule
|
|
||||||
export type Plugin = NuxtConfigurationPlugin
|
|
||||||
export type Render = NuxtConfigurationRender
|
|
||||||
export type Router = NuxtConfigurationRouter
|
|
||||||
export type Server = NuxtConfigurationServer
|
|
||||||
export type ServerMiddleware = NuxtConfigurationServerMiddleware
|
|
||||||
export type VueConfiguration = NuxtConfigurationVueConfiguration
|
|
||||||
export type Watchers = NuxtConfigurationWatchers
|
|
||||||
}
|
|
27
packages/config/types/loading.d.ts
vendored
27
packages/config/types/loading.d.ts
vendored
@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationLoading
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-loading
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface NuxtConfigurationLoading {
|
|
||||||
color?: string
|
|
||||||
continuous?: boolean
|
|
||||||
css?: boolean
|
|
||||||
duration?: number
|
|
||||||
failedColor?: string
|
|
||||||
height?: string
|
|
||||||
rtl?: boolean
|
|
||||||
throttle?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NuxtConfigurationLoadingIndicator
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-loading-indicator
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface NuxtConfigurationLoadingIndicator {
|
|
||||||
background?: string
|
|
||||||
color?: string
|
|
||||||
color2?: string
|
|
||||||
name?: string
|
|
||||||
}
|
|
9
packages/config/types/module.d.ts
vendored
9
packages/config/types/module.d.ts
vendored
@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationModule
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-modules
|
|
||||||
* https://nuxtjs.org/guide/modules
|
|
||||||
*/
|
|
||||||
|
|
||||||
type NuxtConfigurationModuleFunction = (this: any, moduleOptions?: { [key: string]: any }) => Promise<void> | void // this, this.options & this.nuxt TBD
|
|
||||||
|
|
||||||
export type NuxtConfigurationModule = string | [string, { [key: string]: any }] | NuxtConfigurationModuleFunction
|
|
7
packages/config/types/plugin.d.ts
vendored
7
packages/config/types/plugin.d.ts
vendored
@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationPlugin
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-plugins
|
|
||||||
* https://nuxtjs.org/guide/plugins
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type NuxtConfigurationPlugin = { mode?: 'all' | 'client' | 'server', src: string, ssr?: boolean } | string
|
|
28
packages/config/types/render.d.ts
vendored
28
packages/config/types/render.d.ts
vendored
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationRender
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-render
|
|
||||||
* https://ssr.vuejs.org/api/#renderer-options
|
|
||||||
* https://github.com/expressjs/compression#readme
|
|
||||||
* https://github.com/expressjs/serve-static#readme
|
|
||||||
* https://github.com/jshttp/etag#readme
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { CompressionOptions } from 'compression'
|
|
||||||
import { Options as EtagOptions } from 'etag'
|
|
||||||
import { ServeStaticOptions } from 'serve-static'
|
|
||||||
import { BundleRendererOptions } from 'vue-server-renderer'
|
|
||||||
import { NuxtConfigurationServerMiddleware } from './server-middleware'
|
|
||||||
|
|
||||||
export interface NuxtConfigurationRender {
|
|
||||||
bundleRenderer?: BundleRendererOptions
|
|
||||||
compressor?: CompressionOptions | NuxtConfigurationServerMiddleware
|
|
||||||
csp?: any // TBD
|
|
||||||
dist?: ServeStaticOptions
|
|
||||||
etag?: EtagOptions | false
|
|
||||||
fallback?: any // https://github.com/nuxt/serve-placeholder types TBD
|
|
||||||
http2?: any // TBD
|
|
||||||
resourceHints?: boolean
|
|
||||||
ssr?: boolean
|
|
||||||
ssrLog?: boolean | 'collapsed'
|
|
||||||
static?: ServeStaticOptions
|
|
||||||
}
|
|
22
packages/config/types/router.d.ts
vendored
22
packages/config/types/router.d.ts
vendored
@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* NuxtConfigurationRouter
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-router
|
|
||||||
* https://router.vuejs.org/api/#router-construction-options
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { RouterOptions, RouteConfig } from 'vue-router'
|
|
||||||
|
|
||||||
export interface NuxtRouteConfig extends RouteConfig {
|
|
||||||
chunkNames: { [key: string]: string }
|
|
||||||
component?: RouteConfig['component'] | string
|
|
||||||
children?: NuxtRouteConfig[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtConfigurationRouter extends RouterOptions {
|
|
||||||
routeNameSplitter?: string
|
|
||||||
extendRoutes?(routes: NuxtRouteConfig[], resolve: (...pathSegments: string[]) => string): void
|
|
||||||
linkPrefetchedClass?: string
|
|
||||||
middleware?: string | string[]
|
|
||||||
prefetchLinks?: boolean
|
|
||||||
}
|
|
8
packages/config/types/server-middleware.d.ts
vendored
8
packages/config/types/server-middleware.d.ts
vendored
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationServerMiddleware
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-servermiddleware
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { RequestHandler } from 'express'
|
|
||||||
|
|
||||||
export type NuxtConfigurationServerMiddleware = string | { path: string, handler: string | Function } | RequestHandler
|
|
15
packages/config/types/server.d.ts
vendored
15
packages/config/types/server.d.ts
vendored
@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationServer
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-server
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface NuxtConfigurationServer {
|
|
||||||
host?: string
|
|
||||||
https?: {
|
|
||||||
cert?: string | Buffer
|
|
||||||
key?: string | Buffer
|
|
||||||
}
|
|
||||||
port?: number | string
|
|
||||||
socket?: string
|
|
||||||
timing?: boolean | { total?: boolean }
|
|
||||||
}
|
|
9
packages/config/types/vue-configuration.d.ts
vendored
9
packages/config/types/vue-configuration.d.ts
vendored
@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationVueConfiguration
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-vue-config
|
|
||||||
* https://vuejs.org/v2/api/#Global-Config
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { VueConstructor } from 'vue'
|
|
||||||
|
|
||||||
export type NuxtConfigurationVueConfiguration = VueConstructor['config']
|
|
14
packages/config/types/watchers.d.ts
vendored
14
packages/config/types/watchers.d.ts
vendored
@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* NuxtConfigurationWatchers
|
|
||||||
* Documentation: https://nuxtjs.org/api/configuration-watchers
|
|
||||||
* https://github.com/paulmillr/chokidar#api
|
|
||||||
* https://webpack.js.org/configuration/watch/#watchoptions
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
|
||||||
import { WatchOptions as WebpackWatchOptions } from 'webpack'
|
|
||||||
|
|
||||||
export type NuxtConfigurationWatchers = {
|
|
||||||
chokidar?: ChokidarWatchOptions
|
|
||||||
webpack?: WebpackWatchOptions
|
|
||||||
}
|
|
@ -392,18 +392,6 @@ describe('core: resolver', () => {
|
|||||||
expect(resolvedModule).toBe(path)
|
expect(resolvedModule).toBe(path)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should resolve with commonjs for ts module', () => {
|
|
||||||
const resolver = new Resolver({
|
|
||||||
options: {}
|
|
||||||
})
|
|
||||||
resolver.resolvePath = jest.fn(() => '/var/nuxt/resolver/module.ts')
|
|
||||||
resolver.esm = jest.fn(() => ({ default: 'resolved ts module' }))
|
|
||||||
|
|
||||||
expect(() => resolver.requireModule('/var/nuxt/resolver/module')).toThrow(
|
|
||||||
"Cannot find module '/var/nuxt/resolver/module.ts'"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('should throw error if resolvePath failed', () => {
|
test('should throw error if resolvePath failed', () => {
|
||||||
const resolver = new Resolver({
|
const resolver = new Resolver({
|
||||||
options: {}
|
options: {}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export default {
|
|
||||||
build: true
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@nuxt/typescript",
|
|
||||||
"version": "2.8.1",
|
|
||||||
"repository": "nuxt/nuxt.js",
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"dist"
|
|
||||||
],
|
|
||||||
"main": "dist/typescript.js",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/babel__core": "^7.1.2",
|
|
||||||
"@types/chokidar": "^2.1.3",
|
|
||||||
"@types/compression": "^0.0.36",
|
|
||||||
"@types/etag": "^1.8.0",
|
|
||||||
"@types/express": "^4.17.0",
|
|
||||||
"@types/html-minifier": "^3.5.3",
|
|
||||||
"@types/node": "^11.13.18",
|
|
||||||
"@types/optimize-css-assets-webpack-plugin": "^1.3.4",
|
|
||||||
"@types/serve-static": "^1.13.2",
|
|
||||||
"@types/terser-webpack-plugin": "^1.2.1",
|
|
||||||
"@types/webpack": "^4.32.0",
|
|
||||||
"@types/webpack-bundle-analyzer": "^2.13.2",
|
|
||||||
"@types/webpack-dev-middleware": "^2.0.3",
|
|
||||||
"@types/webpack-hot-middleware": "^2.16.5",
|
|
||||||
"consola": "^2.9.0",
|
|
||||||
"fork-ts-checker-webpack-plugin": "^1.4.3",
|
|
||||||
"fs-extra": "^8.1.0",
|
|
||||||
"ts-loader": "^6.0.4",
|
|
||||||
"typescript": "^3.5.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.6.0"
|
|
||||||
},
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
import { exists, readFile, writeJSON } from 'fs-extra'
|
|
||||||
import consola from 'consola'
|
|
||||||
|
|
||||||
export const defaultTsJsonConfig = {
|
|
||||||
compilerOptions: {
|
|
||||||
target: 'esnext',
|
|
||||||
module: 'esnext',
|
|
||||||
moduleResolution: 'node',
|
|
||||||
lib: [
|
|
||||||
'esnext',
|
|
||||||
'esnext.asynciterable',
|
|
||||||
'dom'
|
|
||||||
],
|
|
||||||
esModuleInterop: true,
|
|
||||||
experimentalDecorators: true,
|
|
||||||
allowJs: true,
|
|
||||||
sourceMap: true,
|
|
||||||
strict: true,
|
|
||||||
noImplicitAny: false,
|
|
||||||
noEmit: true,
|
|
||||||
baseUrl: '.',
|
|
||||||
paths: {
|
|
||||||
'~/*': [
|
|
||||||
'./*'
|
|
||||||
],
|
|
||||||
'@/*': [
|
|
||||||
'./*'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
types: [
|
|
||||||
'@types/node',
|
|
||||||
'@nuxt/vue-app'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function setupDefaults (tsConfigPath) {
|
|
||||||
let contents = ''
|
|
||||||
|
|
||||||
if (await exists(tsConfigPath)) {
|
|
||||||
contents = await readFile(tsConfigPath, 'utf-8')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!contents || contents === '{}') {
|
|
||||||
consola.info(`Generating ${tsConfigPath.replace(process.cwd(), '')}`)
|
|
||||||
await writeJSON(tsConfigPath, defaultTsJsonConfig, { spaces: 2 })
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
import { resolve } from 'path'
|
|
||||||
import { mkdirp, readJSON, writeFile, remove, readFile } from 'fs-extra'
|
|
||||||
import { defaultTsJsonConfig, setupDefaults } from '@nuxt/typescript'
|
|
||||||
|
|
||||||
describe('typescript setup', () => {
|
|
||||||
const rootDir = 'tmp'
|
|
||||||
const tsConfigPath = resolve(rootDir, 'tsconfig.json')
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await mkdirp(rootDir)
|
|
||||||
await writeFile(tsConfigPath, '{}', 'utf-8')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('Create tsconfig.json with defaults', async () => {
|
|
||||||
await setupDefaults(tsConfigPath)
|
|
||||||
expect(await readJSON(tsConfigPath)).toEqual(defaultTsJsonConfig)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('Do not override tsconfig.json', async () => {
|
|
||||||
const fooJSON = '{ "foo": 123 }'
|
|
||||||
await writeFile(tsConfigPath, fooJSON, 'utf-8')
|
|
||||||
|
|
||||||
await setupDefaults(tsConfigPath)
|
|
||||||
|
|
||||||
expect(await readFile(tsConfigPath, 'utf-8')).toEqual(fooJSON)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await remove(rootDir)
|
|
||||||
})
|
|
||||||
})
|
|
@ -136,7 +136,7 @@ export const createRoutes = function createRoutes ({
|
|||||||
srcDir,
|
srcDir,
|
||||||
pagesDir = '',
|
pagesDir = '',
|
||||||
routeNameSplitter = '-',
|
routeNameSplitter = '-',
|
||||||
supportedExtensions = ['vue', 'js', 'ts', 'tsx']
|
supportedExtensions = ['vue', 'js']
|
||||||
}) {
|
}) {
|
||||||
const routes = []
|
const routes = []
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"template",
|
"template",
|
||||||
"types/*.d.ts",
|
|
||||||
"vetur"
|
"vetur"
|
||||||
],
|
],
|
||||||
"main": "dist/vue-app.js",
|
"main": "dist/vue-app.js",
|
||||||
"typings": "types/index.d.ts",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"unfetch": "^4.1.0",
|
"unfetch": "^4.1.0",
|
||||||
|
97
packages/vue-app/types/index.d.ts
vendored
97
packages/vue-app/types/index.d.ts
vendored
@ -1,97 +0,0 @@
|
|||||||
import Vue, { ComponentOptions } from 'vue'
|
|
||||||
import VueRouter, { Route } from 'vue-router'
|
|
||||||
import { Store } from 'vuex'
|
|
||||||
import { IncomingMessage, ServerResponse } from 'http'
|
|
||||||
|
|
||||||
// augment typings of NodeJS.Process
|
|
||||||
import './process'
|
|
||||||
|
|
||||||
// augment typings of Vue.js
|
|
||||||
import './vue'
|
|
||||||
|
|
||||||
// augment typings of Vuex
|
|
||||||
import './vuex'
|
|
||||||
|
|
||||||
type Dictionary<T> = { [key: string]: T }
|
|
||||||
|
|
||||||
type NuxtState = Dictionary<any>
|
|
||||||
|
|
||||||
export interface Context {
|
|
||||||
app: NuxtAppOptions
|
|
||||||
/**
|
|
||||||
* @deprecated Use process.client instead
|
|
||||||
*/
|
|
||||||
isClient: boolean
|
|
||||||
/**
|
|
||||||
* @deprecated Use process.server instead
|
|
||||||
*/
|
|
||||||
isServer: boolean
|
|
||||||
/**
|
|
||||||
* @deprecated Use process.static instead
|
|
||||||
*/
|
|
||||||
isStatic: boolean
|
|
||||||
isDev: boolean
|
|
||||||
isHMR: boolean
|
|
||||||
route: Route
|
|
||||||
store: Store<any>
|
|
||||||
env: Dictionary<any>
|
|
||||||
params: Route['params']
|
|
||||||
payload: any
|
|
||||||
query: Route['query']
|
|
||||||
req: IncomingMessage
|
|
||||||
res: ServerResponse
|
|
||||||
redirect(status: number, path: string, query?: Route['query']): void
|
|
||||||
redirect(path: string, query?: Route['query']): void
|
|
||||||
error(params: NuxtError): void
|
|
||||||
nuxtState: NuxtState
|
|
||||||
beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Middleware = string | ((ctx: Context, cb: Function) => Promise<void> | void)
|
|
||||||
|
|
||||||
export interface Transition {
|
|
||||||
name?: string
|
|
||||||
mode?: string
|
|
||||||
css?: boolean
|
|
||||||
duration?: number
|
|
||||||
type?: string
|
|
||||||
enterClass?: string
|
|
||||||
enterToClass?: string
|
|
||||||
enterActiveClass?: string
|
|
||||||
leaveClass?: string
|
|
||||||
leaveToClass?: string
|
|
||||||
leaveActiveClass?: string
|
|
||||||
beforeEnter?(el: HTMLElement): void
|
|
||||||
enter?(el: HTMLElement, done: Function): void
|
|
||||||
afterEnter?(el: HTMLElement): void
|
|
||||||
enterCancelled?(el: HTMLElement): void
|
|
||||||
beforeLeave?(el: HTMLElement): void
|
|
||||||
leave?(el: HTMLElement, done: Function): void
|
|
||||||
afterLeave?(el: HTMLElement): void
|
|
||||||
leaveCancelled?(el: HTMLElement): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtError {
|
|
||||||
message?: string
|
|
||||||
path?: string
|
|
||||||
statusCode?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtLoading extends Vue {
|
|
||||||
fail?(): NuxtLoading
|
|
||||||
finish(): NuxtLoading
|
|
||||||
increase?(num: number): NuxtLoading
|
|
||||||
pause?(): NuxtLoading
|
|
||||||
start(): NuxtLoading
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtAppOptions extends ComponentOptions<Vue> {
|
|
||||||
[key: string]: any // TBD
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NuxtApp extends Vue {
|
|
||||||
$options: NuxtAppOptions
|
|
||||||
$loading: NuxtLoading
|
|
||||||
isOffline: boolean
|
|
||||||
isOnline: boolean
|
|
||||||
}
|
|
14
packages/vue-app/types/process.d.ts
vendored
14
packages/vue-app/types/process.d.ts
vendored
@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* Extends NodeJS.Process interface
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare namespace NodeJS {
|
|
||||||
interface Process {
|
|
||||||
browser: boolean
|
|
||||||
client: boolean
|
|
||||||
mode: 'spa' | 'universal'
|
|
||||||
modern: boolean
|
|
||||||
server: boolean
|
|
||||||
static: boolean
|
|
||||||
}
|
|
||||||
}
|
|
30
packages/vue-app/types/vue.d.ts
vendored
30
packages/vue-app/types/vue.d.ts
vendored
@ -1,30 +0,0 @@
|
|||||||
/**
|
|
||||||
* Extends interfaces in Vue.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Vue, { ComponentOptions } from 'vue'
|
|
||||||
import { Route } from 'vue-router'
|
|
||||||
import { MetaInfo } from 'vue-meta'
|
|
||||||
import { Context, Middleware, Transition, NuxtApp } from './index'
|
|
||||||
|
|
||||||
declare module 'vue/types/options' {
|
|
||||||
interface ComponentOptions<V extends Vue> {
|
|
||||||
asyncData?(ctx: Context): object | undefined
|
|
||||||
fetch?(ctx: Context): Promise<void> | void
|
|
||||||
head?: MetaInfo | (() => MetaInfo)
|
|
||||||
key?: string | ((to: Route) => string)
|
|
||||||
layout?: string | ((ctx: Context) => string)
|
|
||||||
loading?: boolean
|
|
||||||
middleware?: Middleware | Middleware[]
|
|
||||||
scrollToTop?: boolean
|
|
||||||
transition?: string | Transition | ((to: Route, from: Route) => string)
|
|
||||||
validate?(ctx: Context): Promise<boolean> | boolean
|
|
||||||
watchQuery?: boolean | string[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module 'vue/types/vue' {
|
|
||||||
interface Vue {
|
|
||||||
$nuxt: NuxtApp
|
|
||||||
}
|
|
||||||
}
|
|
@ -159,7 +159,7 @@ export default class WebpackBaseConfig {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts', '.tsx'],
|
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx'],
|
||||||
alias: this.alias(),
|
alias: this.alias(),
|
||||||
modules: webpackModulesDir
|
modules: webpackModulesDir
|
||||||
},
|
},
|
||||||
@ -262,26 +262,6 @@ export default class WebpackBaseConfig {
|
|||||||
},
|
},
|
||||||
use: perfLoader.js().concat(babelLoader)
|
use: perfLoader.js().concat(babelLoader)
|
||||||
},
|
},
|
||||||
{
|
|
||||||
test: /\.ts$/i,
|
|
||||||
use: [
|
|
||||||
babelLoader,
|
|
||||||
{
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: this.loaders.ts
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.tsx$/i,
|
|
||||||
use: [
|
|
||||||
babelLoader,
|
|
||||||
{
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: this.loaders.tsx
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
test: /\.css$/i,
|
test: /\.css$/i,
|
||||||
oneOf: styleLoader.apply('css')
|
oneOf: styleLoader.apply('css')
|
||||||
@ -422,22 +402,14 @@ export default class WebpackBaseConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
warningIgnoreFilter () {
|
warningIgnoreFilter () {
|
||||||
const { buildOptions, options: { _typescript = {} } } = this.buildContext
|
|
||||||
const filters = [
|
const filters = [
|
||||||
// Hide warnings about plugins without a default export (#1179)
|
// Hide warnings about plugins without a default export (#1179)
|
||||||
warn => warn.name === 'ModuleDependencyWarning' &&
|
warn => warn.name === 'ModuleDependencyWarning' &&
|
||||||
warn.message.includes(`export 'default'`) &&
|
warn.message.includes(`export 'default'`) &&
|
||||||
warn.message.includes('nuxt_plugin_'),
|
warn.message.includes('nuxt_plugin_'),
|
||||||
...(buildOptions.warningIgnoreFilters || [])
|
...(this.buildContext.buildOptions.warningIgnoreFilters || [])
|
||||||
]
|
]
|
||||||
|
|
||||||
if (_typescript.build && buildOptions.typescript && buildOptions.typescript.ignoreNotFoundWarnings) {
|
|
||||||
filters.push(
|
|
||||||
warn => warn.name === 'ModuleDependencyWarning' &&
|
|
||||||
/export .* was not found in /.test(warn.message)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return warn => !filters.some(ignoreFilter => ignoreFilter(warn))
|
return warn => !filters.some(ignoreFilter => ignoreFilter(warn))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import querystring from 'querystring'
|
import querystring from 'querystring'
|
||||||
import consola from 'consola'
|
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import HTMLPlugin from 'html-webpack-plugin'
|
import HTMLPlugin from 'html-webpack-plugin'
|
||||||
import BundleAnalyzer from 'webpack-bundle-analyzer'
|
import BundleAnalyzer from 'webpack-bundle-analyzer'
|
||||||
@ -89,7 +88,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
|
|
||||||
plugins () {
|
plugins () {
|
||||||
const plugins = super.plugins()
|
const plugins = super.plugins()
|
||||||
const { buildOptions, options: { appTemplatePath, buildDir, modern, rootDir, _typescript = {} } } = this.buildContext
|
const { buildOptions, options: { appTemplatePath, buildDir, modern } } = this.buildContext
|
||||||
|
|
||||||
// Generate output HTML for SSR
|
// Generate output HTML for SSR
|
||||||
if (buildOptions.ssr) {
|
if (buildOptions.ssr) {
|
||||||
@ -150,19 +149,6 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeScript type checker
|
|
||||||
// Only performs once per client compilation and only if `ts-loader` checker is not used (transpileOnly: true)
|
|
||||||
if (_typescript.build && buildOptions.typescript && buildOptions.typescript.typeCheck && !this.isModern && this.loaders.ts.transpileOnly) {
|
|
||||||
const ForkTsCheckerWebpackPlugin = require(this.buildContext.nuxt.resolver.resolveModule('fork-ts-checker-webpack-plugin'))
|
|
||||||
plugins.push(new ForkTsCheckerWebpackPlugin(Object.assign({
|
|
||||||
vue: true,
|
|
||||||
tsconfig: path.resolve(rootDir, 'tsconfig.json'),
|
|
||||||
tslint: false, // We recommend using ESLint so we set this option to `false` by default
|
|
||||||
formatter: 'codeframe',
|
|
||||||
logger: consola
|
|
||||||
}, buildOptions.typescript.typeCheck)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
test/fixtures/typescript/layouts/default.vue
vendored
12
test/fixtures/typescript/layouts/default.vue
vendored
@ -1,12 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Nuxt />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
middleware: 'test'
|
|
||||||
})
|
|
||||||
export default class DefaultLayout extends Vue {}
|
|
||||||
</script>
|
|
1
test/fixtures/typescript/middleware/test.ts
vendored
1
test/fixtures/typescript/middleware/test.ts
vendored
@ -1 +0,0 @@
|
|||||||
export default () => {}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user