-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript support for config file (vue.config.ts) #2138
Comments
Yeah could be nice to have. Also /cc @octref Is there anyway for VSCode to have special type checking / autocomplete for |
I think we could have something like webpack does: // vue.config.ts
import { Config } from '@vue/cli-service'
const config: Config = {
// ...
}
export default config If anyone want to work on this that'd be great. /cc @ktsn @HerringtonDarkholme |
JS/TS have different story for type checking / autocomplete than JSON. They are actually closer to what we have in Vetur — finding out the default export and wrap that in a typed function call. We have plan on our roadmap to support linting / autocomplete for webpack and I believe when it's done it can be easily used to support |
I'll work on the |
Any updates on this? |
We might as well enable JS type checking on On {
"compilerOptions": {
// ...
"checkJs": true,
},
"include": [
// ...
"vue.config.js"
],
// ...
} Then import /**
* @typedef { import("@vue/cli-service").ProjectOptions } Options
*/ Importing the definitions other ways didn't worked for me. Also on vscode I'm not getting any type checking errors, only code completions. Here's a working example with code completion working in vscode even inside // vue.config.js
/**
* @typedef { import("@vue/cli-service").ProjectOptions } Options
*/
const { ProvidePlugin } = require('webpack')
const { resolve, join } = require('path')
/** @param args {string[]} */
const path = (...args) => resolve(join(__dirname, ...args))
/** @type {Options} */
const options = {
devServer: {
host: 'bp.viz',
port: 80,
},
chainWebpack: config => {
config.merge({
resolve: {
modules: ['node_modules', path('src')],
},
devtool: 'source-map',
})
config.plugin('provide').use(ProvidePlugin, [
{
Component: ['vue-property-decorator', 'Component'],
Base: ['./src/components/Base', 'Base'],
},
])
},
}
module.exports = options |
Can confirm this works! My vue.config.js: /**
* @type { ProjectOptions }
*/
module.exports = {
css: {
sourceMap: true,
},
configureWebpack: {
target: 'electron-renderer',
},
lintOnSave: false,
chainWebpack: config => {
const svgRules = config.module.rule('svg')
// Remove default svg loader
svgRules.uses.clear()
// Instead use raw-loader
svgRules.use('raw-loader').loader('raw-loader')
},
} |
Here's my vue.config.js config
|
It works without
|
What's the status of vue.config.ts support? |
(function (exports, require, module, __filename, __dirname) { import * as path from 'path'; SyntaxError: Unexpected token * |
Would like this too. I'm writing scripts for prerendering that I call in my vue.config.js and I prefer to write everything in TypeScript. |
Any update on this? Also might be a good idea to add ability to specify path to Aside of type checking this will make it easier to reuse ts code from your codebase. Currently I'm using My IDE does a good job on type-checking and auto-completion but I have to import all utils as |
Note: Webpack itself does support various languages for their config files: https://webpack.js.org/configuration/configuration-languages/ |
vue.config.ts doesn't work yet, see vuejs/vue-cli#2138
Support? |
Bump, I need to import some things from .ts files, would be really nice to have this feature. What are my other options, if any? Edit:
seem to do the trick, but ES6 import/export still doesn't work, so I guess I'll just copy the code over? |
@GrayStrider you can create require('ts-node').register({
project: _PATH_TO_TSCONFIG_WITH_COMMONJS_,
})
module.exports = require("./vue.config.ts").config; And then your import { ProjectOptions } from "@vue/cli-service"
export const config: ProjectOptions = {
// ... your vue config here
}; Now you have type checks and code completion in your vue config. I keep additional |
Any changes? |
Bump, looking forward to this 🙏 Any updates? |
I've created
Added script to package.json Added Now if i've changed configuration i just need to type: I use pnpm, not yarn or npm |
Would love to see |
I did it!!!
{
"scripts": {
// a little ugly, it can be optimized
"serve": "cross-env VUE_CLI_SERVICE_CONFIG_PATH=./vue.config.ts ts-node ./node_modules/@vue/cli-service/bin/vue-cli-service.js serve"
},
}
|
@n1kk 's solution seems cleaner. I had to add require('ts-node').register({
project: _PATH_TO_TSCONFIG_WITH_COMMONJS_,
});
require('tsconfig-paths/register'); // In case you need paths
module.exports = require("./vue.config.ts").config; |
Any progress on this? |
Finally got it working. vue.config.js:
vue.config.ts:
|
What problem does this feature solve?
Type tracking when configured.
What does the proposed API look like?
can config width:
vue.config.ts
or
vue.config.js
:The text was updated successfully, but these errors were encountered: