2016-12-05 3 views
1

Я следую этому руководству. http://www.c-sharpcorner.com/article/using-mvc-6-and-angularjs-2-with-net-core/Gulp не копирует Angular2 в lib-npm

Я получил возможность использовать gulp для копирования файлов в папку lib-npm. Все ожидаемые файлы копируются, кроме угловых. Я не получаю сообщение об ошибке, файлы просто есть.

вот мой Глоток файл

/// <binding /> 
/* 
This file in the main entry point for defining Gulp tasks and using Gulp plugins. 
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007 
*/ 
"use strict"; 
var gulp = require("gulp"); 
var root_path = { 
    webroot: "./wwwroot/" 
}; 
//library source 
root_path.nmSrc = "./node_modules/"; 
//library destination 
root_path.package_lib = root_path.webroot + "lib-npm/"; 
gulp.task("copy-systemjs", function() { 
    return gulp.src(root_path.nmSrc + '/systemjs/dist/**/*.*', { 
     base: root_path.nmSrc + '/systemjs/dist/' 
    }).pipe(gulp.dest(root_path.package_lib + '/systemjs/')); 
}); 
gulp.task("copy-angular2", function() { 
    return gulp.src(root_path.nmSrc + '/angular2/bundles/**/*.js', { 
     base: root_path.nmSrc + '/angular2/bundles/' 
    }).pipe(gulp.dest(root_path.package_lib + '/angular2/')); 
}); 
gulp.task("copy-es6-shim", function() { 
    return gulp.src(root_path.nmSrc + '/es6-shim/es6-sh*', { 
     base: root_path.nmSrc + '/es6-shim/' 
    }).pipe(gulp.dest(root_path.package_lib + '/es6-shim/')); 
}); 
gulp.task("copy-rxjs", function() { 
    return gulp.src(root_path.nmSrc + '/rxjs/bundles/*.*', { 
     base: root_path.nmSrc + '/rxjs/bundles/' 
    }).pipe(gulp.dest(root_path.package_lib + '/rxjs/')); 
}); 
gulp.task("copy-all", ["copy-rxjs", 'copy-angular2', 'copy-systemjs', 'copy-es6-shim']); 

Я также заметил, что моя. \ Node_modules \ папка Angular2 в моем проекте не имеет .js файлов в нем. Это нормально?

Angular2 версия 1.0.2

Я получаю следующие ошибки в сборке, поскольку отсутствуют файлы

Cannot find name 'Component'. 
Build:Cannot find module 'angular2/core'. 
Build:Cannot find module 'angular2/platform/browser'. 
Build:Cannot find name 'Component'. 
Cannot find module 'angular2/core'. 
Cannot find module 'angular2/platform/browser' 

ответ

1

Я хотел бы предложить вам не копировать node_modules каждый раз, когда вы строите приложение. Вы можете легко изменить промежуточное ПО UseStaticFiles внутри класса Startup.cs, как описано here. Делая это, ваши node_modules остаются там, где они есть, и вам не нужно их многократно копировать.

КПП. В последнее время (перед переключением на UseStatisFiles модификации) Я сделал то же самое в Gulp и следующий работал хорошо:

gulp.task('build-angular-js', function() { 
    return gulp.src(paths.angularJs) 
     .pipe(cache('linting')) 
     .pipe(gulp.dest(paths.jsNgDest)); 
}); 

..where paths равна:

var paths = { 
    webroot: "./wwwroot/", 
    angularJs: [ 
     "./node_modules/core-js/client/shim.min.js", 
     "./node_modules/zone.js/dist/zone.js", 
     "./node_modules/reflect-metadata/Reflect.js", 
     "./node_modules/systemjs/dist/system.src.js", 
     "./App/External/systemjs.config.js", 

     "./node_modules/@angular/**/*.js", 
     "./node_modules/rxjs/**/*.js" 
    ], 
    appJs: [ 
     "./App/App/**/*.js" 
    ] 
}; 
paths.jsDest = paths.webroot + "app"; 
paths.jsNgDest = paths.webroot + "app"; 

Полный шаблон и все источники, включая gulpfile.js, можно найти здесь: GitHub. Обратите внимание, что cache является плагином gulp, чтобы избежать копирования не измененных файлов. Как сказано выше, лучше избегать копирования node_modules.

+0

Извините, но не исправить проблему У меня все еще есть угловые файлы в моей папке lib-npm, и я получаю ошибки сборки, которых они не хватает. Не удается найти имя «Компонент». Сборка: Не удается найти модуль «угловой2/сердечник». Сборка: Невозможно найти модуль 'angular2/platform/browser'. Сборка: Не удается найти имя «Компонент». Не удается найти модуль 'angular2/core'. Не удается найти модуль 'angular2/platform/browser'. – TheColonel26

+1

Оказывается, я использовал неправильный угловой пакет 2, это был старый пакет перед выпуском. Но я принял ваш совет, и я использую трюк статических файлов. – TheColonel26

Смежные вопросы