앵귤러 CLI 도구로 새 프로젝트를 시작했습니다. 그 다음 나는 밑줄을 가져 오기 위해 this official guide을 따른다. 그리고 나는 정확하게가 말하는 를한다.언더 코어를 앵귤러 2 CLI 프로젝트로 가져 오기
하지만 여전히 브라우저에서 내 프로젝트 충돌 내가 오류 메시지가 내 app.component에 밑줄을 사용하려고하면 밑줄이 DIST/공급 업체 폴더에 추가됩니다
ORIGINAL EXCEPTION: ReferenceError: _ is not defined
그래서 내 생각이 있다는 것 문제는 Systemjs 구성에 있습니다.
"use strict";
// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md
/***********************************************************************************************
* User Configuration.
**********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
'underscore': 'vendor/underscore/',
};
/** User packages configuration. */
const packages: any = {
'underscore': { main: 'underscore.js', format: 'cjs' },
};
////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
* Everything underneath this line is managed by the CLI.
**********************************************************************************************/
const barrels: string[] = [
// Angular specific barrels.
'@angular/core',
'@angular/common',
'@angular/compiler',
'@angular/forms',
'@angular/http',
'@angular/router',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
// Thirdparty barrels.
'rxjs',
// App specific barrels.
'app',
'app/shared',
/** @cli-barrel */
];
const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
cliSystemConfigPackages[barrelName] = { main: 'index' };
});
/** Type declaration for ambient System. */
declare var System: any;
// Apply the CLI SystemJS configuration.
System.config({
map: {
'@angular': 'vendor/@angular',
'rxjs': 'vendor/rxjs',
'main': 'main.js'
},
packages: cliSystemConfigPackages
});
// Apply the user's configuration.
System.config({ map, packages });
내 app.component : 내가 가서 할
/// <reference path="../../typings/globals/underscore/index.d.ts" />
import { Component } from '@angular/core';
declare var _;
@Component({
moduleId: module.id,
selector: 'app-root',
template: `<h1>{{title}}</h1>`
})
export class AppComponent {
title = _.version;
}
여기
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
sassCompiler: {
includePaths: [
'src/styles'
]
},
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(ts|js|js.map)',
'rxjs/**/*.+(js|js.map)',
'underscore/underscore.js',
'@angular/**/*.+(js|js.map)'
]
});
};
내 시스템 설정입니다 : 여기 내 각-CLI 빌드입니다 잘못된? 왜이 이렇게 복잡합니까? 공동체가 단순한 제 3 자 라이브러리를 추가하는 것이 번거롭다는 것을 받아 들일 수 있습니까?
이며 작동하지 않습니다. 이 작업을 수행하기 위해 system.js 설정이 어떻게 나타나야합니까? – mottosson
저는 실제로 밑줄을 모르지만 각 lib에 달려 있습니다. 그러나 코드는 정확할 수 있습니다 (정확하게 알지 못하기 때문에 말할 수 있습니다). 어떤 버전의 밑줄을 사용하고 있습니까? dev 또는 프로덕션 종속성으로 가져 오시겠습니까? – acdcjunior
버전 1.8.3을 사용하고 정규 종속성에 추가했습니다. 라이브러리가 dist/vendor 폴더에 추가되었으므로, angular-cli-build가 정확하고 문제가 systemjs config라고 추측합니다. – mottosson