【发布时间】:2021-01-06 09:38:02
【问题描述】:
我像这样开箱即用地生成了一个新的 Vue 应用程序:
? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, TS, PWA, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Choose a version of Vue.js that you want to start the project with 3.x (Preview)
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
? Pick a linter / formatter config: Prettier
? Pick additional lint features: Lint on save, Lint and fix on commit
? Pick a unit testing solution: Jest
? Pick an E2E testing solution: WebdriverIO
? Pick browsers to run end-to-end test on Chrome
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
向 VS Code 添加了一个 launch.json,如下所示:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
像这样在我的项目根目录中添加了一个 vue.config.js:
module.exports = {
configureWebpack: {
devtool: 'source-map'
}
}
在 main.ts 中放一个断点:
createApp(App)
.use(store)
.use(router)
.mount("#app");
从命令行运行 npm run serve 并在 VS Code 中按 F5。没有休息。我该如何解决这个问题? Typescript 不适合 Vue 吗?我以前做过 JS 项目。
【问题讨论】:
-
sourceMapOverrides 部分是很多人解决这个问题的地方,我需要在 src 之前有一段时间,比如 \\\.\src,我认为在浏览器中查看 webpack 源文件树会告诉你什么它正在使用的“文件夹”。
-
"sourceMapPathOverrides": { "webpack:///./src/*": "${webRoot}/src/*" }
标签: typescript vue.js visual-studio-code vscode-debugger