如何使用TypeScript支持创建Nuxt构建?
我正在尝试使用命令“npm run build”构建一个nuxtjs应用程序,该命令正在执行“nuxt build” 但是,构建失败,看起来nuxt不知道如何编译Typescript代码。但有趣的是,“npm run dev”命令可以毫无问题地工作,应用程序也可以工作。只是生产构建失败了 我注意到,如果我从我的单文件组件中的script标记中删除lang=“ts”,错误就消失了,但是当然,typescript代码不会编译,并且会发生其他错误。 我尝试了各种tsconfig.json配置,但没有一种是有效的。 我在package.json文件的依赖项中包含了typescript和ts加载程序模块如何使用TypeScript支持创建Nuxt构建?,typescript,vue.js,nuxt.js,Typescript,Vue.js,Nuxt.js,我正在尝试使用命令“npm run build”构建一个nuxtjs应用程序,该命令正在执行“nuxt build” 但是,构建失败,看起来nuxt不知道如何编译Typescript代码。但有趣的是,“npm run dev”命令可以毫无问题地工作,应用程序也可以工作。只是生产构建失败了 我注意到,如果我从我的单文件组件中的script标记中删除lang=“ts”,错误就消失了,但是当然,typescript代码不会编译,并且会发生其他错误。 我尝试了各种tsconfig.json配置,但没有一
"ts-loader": "^5.3.3",
"typescript": "^3.3.3",
这是运行“npm运行构建”时收到的错误消息示例
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
]
},
"noUnusedLocals": true,
"resolveJsonModule": true,
"esModuleInterop": true
}
}
有人知道如何让NuxtJs与Typescript一起用于生产构建,而不仅仅是用于开发吗
谢谢您应该使用nuxt ts
请参见此处的一些文档和示例
不久将有更多的文档出现您应该使用nuxt ts
请参见此处的一些文档和示例
很快就会有更多的文档最终的解决方案是(正如@Aldarund所建议的那样)使用nuxt ts,但没有任何额外的typescript模块,如typescript或nuxt typescript。您甚至不需要ts加载模块。
而nuxt.config.js必须重命名为nuxt.config.ts
更不用说您必须在npm脚本中只使用nuxt ts,而不是普通的nuxt
编辑2019年4月:
从Nuxt.js的2.5.0版本开始,不再需要Nuxt ts来支持typescript。通过安装@Nuxt/typescript,Nuxt.js正式支持typescript
最终的解决方案(如@Aldarund)建议使用nuxt ts,但不使用任何额外的typescript模块,如typescript或nuxt typescript。您甚至不需要ts加载模块。
而nuxt.config.js必须重命名为nuxt.config.ts
更不用说您必须在npm脚本中只使用nuxt ts,而不是普通的nuxt
编辑2019年4月:
从Nuxt.js的2.5.0版本开始,不再需要Nuxt ts来支持typescript。通过安装@Nuxt/typescript,Nuxt.js正式支持typescript
谢谢,如果我找不到使用基本Nuxt.js的解决方案,我会试试看:)@papazulu ye但它是基本Nuxt just,这是使用ts和Nuxt的新官方方式谢谢,如果我找不到使用基本Nuxt.js的解决方案,我会试试看:)@papazulu ye但它是基本Nuxt just,将ts与NUXT一起使用是一种新的官方方式,这里对我来说重要的是“删除
typescript
”。谢谢。这里对我来说最重要的是“删除typescript
”。非常感谢。
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
]
},
"noUnusedLocals": true,
"resolveJsonModule": true,
"esModuleInterop": true
}
}