我正在努力使 vue.jstypescript 一起工作 . 但是当我编译vue源代码时,我的index.html上有“ Uncaught ReferenceError: require is not defined ” .

这是我做的:

tsconfig.json

{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"lib": [
  "dom",
  "es5",
  "es2015.promise"
]
},
"include": [
  "scripts/**/*"
],
"exclude": [
  "node_modules",
  "wwwroot"
],
"compileOnSave": true
}

scripts/test.ts (来自vue.js docs

import Vue from 'vue'
import Component from 'vue-class-component'
// The @Component decorator indicates the class is a Vue component
@Component({
  // All component options are allowed in here
  template: '<button @click="onClick">Click!</button>'
})
export default class MyComponent extends Vue {
  // Initial data can be declared as instance properties
  message: string = 'Hello!'
  // Component methods can be declared as instance methods
  onClick(): void {
    window.alert(this.message)
  }
}

package.json

"dependencies": {
  "vue": "^2.2.6",
  "vue-router": "^2.4.0"
},
"devDependencies": {
  "vue-class-component": "^5.0.1"
}

我没有使用node.js(我不想),只有npm才能下载依赖项 . 我也在Visual Studio 2017中工作,应用程序在.net核心服务器上运行 .