typescript - How do I add a typescript module to Nuxt Config?
问题描述
How do I add the typescript file to my build? It is a configuration file.
To reproduce
% npm create nuxt-app play-ts-nuxt
create-nuxt-app v3.6.0
✨ Generating Nuxt.js project in play-ts-nuxt
? Project name: play-ts-nuxt
? Programming language: TypeScript
? Package manager: Npm
? UI framework: Buefy
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Linting tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Testing framework: Jest
? Rendering mode: Universal (SSR / SSG)
? Deployment target: Server (Node.js hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Continuous integration: None
? Version control system: Git
Then convert nuxt.config.js to nuxt.config.ts
I changed some require code
build: {
vendor: [],
publicPath: `/${require('./secrets.json').NODE_ENV}/_nuxt/` // <= add the path to the cached files
},
To typescript
import envConfiguration from './env-configuration'
build: {
publicPath: `/${envConfiguration.NODE_ENV}/_nuxt/` // <= add the path to the cached files
},
I get an error that the env-configuration.ts file is not in .build. It is in the root of the project, how do I add it to the build?
Error: Cannot find module './env-configuration'
Require stack:
- ...uploader/.build/nuxt.config.js
解决方案
推荐阅读
- javascript - Checkmarx says document.url is unsafe
- sql - 引用父别名时将外部应用转换为左连接
- ios - 如何获得本地化的字母 Swift iOS
- php - PHP exec命令不适用于ImageMagick
- python - 如何遍历数据框,添加 3 个特定行,用它们的总和替换这 3 行,然后每 57 行重复一次?
- python - 我想用python开发一个谈话程序
- javascript - 将对象的属性和值提取到新对象中
- html - 文档为空( lxml.etree.ParserError: Document is empty )
- python - 序列上的迭代器
- excel - Excel 无法将宏分配给按钮