NDY*_*NDY 6 npm angularjs gruntjs typescript angular
题
为什么我的Grunt Typescript编译器找不到角度核心?
我想它与路径有关,所以编译器无法在node_modules目录中找到libs.
错误
typescript/add.component.ts(1,25):错误TS2307:找不到模块'angular2/core'.
建立
Gruntfile.js任务
typescript: {
all: {
src: ['typescript/**/*.ts'],
dest: 'javascript/frontend',
options: {
target: "es5",
module: "system",
moduleResolution: "node",
emitDecoratorMetadata: true,
experimentalDecorators: true,
removeComments: false,
noImplicitAny: false
}
}
Run Code Online (Sandbox Code Playgroud)
打字稿/ add.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'mytest',
template: '<h1>test</h1>'
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
node_modules
文件路径
app -- node_modules
-- typescript
-- app.component.ts
-- Gruntfile.js
-- package.json
Run Code Online (Sandbox Code Playgroud)
使用过的libs/frameworks/tutorials
刚才我遇到了同样的问题。在详细模式下运行 grunt 显示了从 grunt 配置生成的 ts 配置文件的内容。更仔细地观察,这表明 moduleResolution 选项根本没有被使用。但是,另一方面,官方 grunt-typescript 页面上也没有对此进行描述。
不管怎样,长话短说:我已经使用了grunt-ts包,一切都很顺利!为了您的方便,我在下面发布了我的配置:-)
module.exports = function(grunt) {
grunt.initConfig({
ts: {
base: {
src: ['src/**/*.ts'],
dest: 'dist',
options: {
module: 'system',
moduleResolution: 'node',
target: 'es5',
experimentalDecorators: true,
emitDecoratorMetadata: true,
noImplicitAny: false
}
}
}
});
grunt.loadNpmTasks('grunt-ts');
grunt.registerTask('default', ['ts']);
};Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2870 次 |
| 最近记录: |