简体   繁体   English

我正在尝试找到一个具有使用最新@angular库创建dist文件夹的gulp的angular2应用

[英]I'm trying to find an angular2 app that has gulp for creating a dist folder using the latest @angular libraries

I'm trying to find an angular2 app that has gulp for creating a dist folder using the latest @angular libraries. 我正在尝试找到一个具有使用最新@angular库创建dist文件夹的gulp的angular2应用。

I can find some online but they dont use latest @angulae libs and gulp. 我可以在网上找到一些,但是他们不使用最新的@angulae库和gulp。

I'm also using system.js to boot the app locally, so I need to see an example of how that works for a dist deployment folder thats bundled. 我还使用system.js在本地启动该应用程序,因此我需要查看一个示例,该示例如何用于捆绑的dist部署文件夹。

My main requirements for the app I'm trying to build is: 我对要构建的应用程序的主要要求是:

  • Gulp. 喝了
  • Angular2. 角度2。
  • Latest Angular 2 libs with http and routing libs added. 最新的Angular 2库增加了http和路由库。
  • System.js used. 使用System.js。
  • Typescript. 打字稿。
  • All the ts files bundles into one file for dist folder. 所有ts文件都捆绑到dist文件夹的一个文件中。

This is my main.ts file: 这是我的main.ts文件:

import { APP_BASE_HREF } from '@angular/common';
import { enableProdMode, provide } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS, Http, Headers} from '@angular/http';

import {ROUTER_DIRECTIVES, Router, ROUTER_BINDINGS, RouterOutlet, RouteConfig, RouterLink, ROUTER_PROVIDERS, CanActivate, OnActivate,
    ComponentInstruction} from '@angular/router-deprecated';

import { AppComponent } from './app.component';

if ('<%= ENV %>' === 'prod') { enableProdMode(); }

import {AuthService} from './services/authService/authService';
import {SocialService} from './services/socialService/socialService';
import {UserService} from './services/userService/userService';
import {OrganisationService} from './services/organisationService/organisationService';
import {NotificationService} from './services/notificationService/notificationService';
import {ApplicationService} from './services/applicationService/applicationService';
import {JobService} from './services/jobService/jobService';
import {MessageService} from './services/messageService/messageService';
import {EmailService} from './services/emailService/emailService';

import {Environment} from './models/environment/environment';

import {LoggedInRouterOutlet} from './interceptor';

bootstrap(AppComponent, [
    ROUTER_PROVIDERS,
    provide(APP_BASE_HREF, { useValue: '<%= APP_BASE %>' }),
    HTTP_PROVIDERS,
    Environment,
    AuthService, 
    ApplicationService,
    EmailService,
    SocialService, 
    UserService,
    JobService,
    MessageService, 
    EmailService, 
    OrganisationService, 
    NotificationService
]);

Folder Structure And Git Bash Error 文件夹结构和Git Bash错误

在此处输入图片说明

I've been looking for exactly the same thing, and it's been challenging, especially when it comes to bundling. 我一直在寻找完全相同的东西,而且一直很具挑战性,尤其是在捆绑方面。

This repo has what you're asking for (as far as I can tell), but it's far more complicated than I'm hoping for. 这个仓库已经满足您的要求(据我所知),但是它比我希望的要复杂得多。 And its build is currently failing. 而且它的构建当前正在失败。

Last night I was finally able to get this working, but I haven't checked to see whether source maps and such are going to work. 昨晚我终于能够使它正常工作,但是我没有检查是否可以使用源地图等。 I started by following the 5-minute quickstart pretty closely (ie make sure you're using the version of Node they recommend), but making a few adjustments based on my project's setup. 首先,我非常仔细地遵循了5分钟的快速入门 (即确保您使用的是他们推荐的Node版本),但是根据我的项目的设置进行了一些调整。

gulpfile.js gulpfile.js

var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var cleanCSS = require('gulp-clean-css');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var ts = require('gulp-typescript');
var SystemBuilder = require("systemjs-builder");

var paths = {
    dist: 'client/dist',
    tsconfig: 'tsconfig.json'
}

gulp.task('scripts:startup', function() {
    return gulp.src([
            'core-js/client/shim.min.js',
            'zone.js/dist/zone.js',
            'reflect-metadata/Reflect.js'
        ], { cwd: 'node_modules' })
        .pipe(concat('startup.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('client/dist'));
});


gulp.task('scripts:app', function() {
    var tsResult = tsProject.src()
        .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(ts(tsProject));
    return tsResult.js
        //.pipe(uglify())
        .pipe(sourcemaps.write('../maps', { includeContent: false, sourceRoot: '/client/app' }))
        .pipe(gulp.dest('client/dist/app'));
});

gulp.task('scripts:bundle',
    function () {
        var builder = new SystemBuilder('.', 'systemjs.config.js');
        return builder.buildStatic('app', 'client/dist/app.js');
    });

gulp.task('scripts', ['scripts:startup', 'scripts:app', "scripts:bundle"]);

gulp.task('default', ['scripts', 'styles'], function () {
});

package.json 的package.json

{
    ...
    "private": true,
    "scripts": {
        "start": "tsc",
        "lite": "lite-server",
        "postinstall": "typings install",
        "tsc": "tsc",
        "typings": "typings"
    },
    "devDependencies": {
        "gulp": "^3.9.1",
        "gulp-concat": "^2.6.0",
        "gulp-uglify": "^1.5.3",
        "gulp-sourcemaps": "^1.5.2",
        "gulp-clean-css": "^2.0.7",
        "gulp-cached": "^1.1.0",
        "gulp-remember": "^0.3.1",
        "gulp-typescript": "~2.13.4",
        "systemjs-builder": "~0.15.19",
        "typescript": "~1.8.10",
        "typings": "~1.0.4"
    },
    "dependencies": {
        "@angular/common": "2.0.0-rc.1",
        "@angular/compiler": "2.0.0-rc.1",
        "@angular/core": "2.0.0-rc.1",
        "@angular/http": "2.0.0-rc.1",
        "@angular/platform-browser": "2.0.0-rc.1",
        "@angular/platform-browser-dynamic": "2.0.0-rc.1",
        "@angular/router": "2.0.0-rc.1",
        "@angular/router-deprecated": "2.0.0-rc.1",
        "@angular/upgrade": "2.0.0-rc.1",

        "systemjs": "0.19.27",
        "core-js": "^2.4.0",
        "reflect-metadata": "^0.1.3",
        "rxjs": "5.0.0-beta.6",
        "zone.js": "^0.6.12",

        "angular2-in-memory-web-api": "0.0.11",
        "bootstrap": "^3.3.6"
    }
}

Index.html Index.html

<!DOCTYPE html>
<html>
<head>
    <title>Precise Patient Registry</title>
    <meta charset="utf-8"/>
    <script src="client/dist/startup.min.js"></script>
    <script src="client/dist/app.js"></script>
</head>
<body>

    <ppr-app>Loading...</ppr-app>

</body>
</html>

tsconfig.json tsconfig.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "node_modules",
        "node_modules/typescript",
        "typings/index.d.ts"
    ]
}

typings.json Types.json

{
    "globalDependencies": {
        "core-js": "registry:dt/core-js#0.0.0+20160317120654",
        "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
        "node": "registry:dt/node#4.0.0+20160509154515"
    }
}

systemjs.config.js systemjs.config.js

(function (global) {
    // map tells the System loader where to look for things
    var map = {
        'app': 'client/dist/app', 
        '@angular': 'node_modules/@angular',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        'rxjs': 'node_modules/rxjs'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app': { main: 'main.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { defaultExtension: 'js' },
    };
    var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router',
    'router-deprecated',
    'upgrade'
    ];
    // Add package entries for angular packages
    ngPackageNames.forEach(function (pkgName) {
        packages['@angular/' + pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
    });
    var config = {
        map: map,
        packages: packages
    }
    System.config(config);
})(this);

Also, if you've already got a project that has stuff from an older version of angular, be sure to prune npm and typings: 另外,如果您已经有一个包含旧版本的angular的东西的项目,请确保修剪npm和键入内容:

npm prune
npm install
npm run typings prune

Otherwise the old polyfills tend to get in the way of typescript compiling. 否则,旧的polyfill会妨碍打字稿的编译。

Please, please , keep me updated if you make improvements to this. 拜托, 拜托 ,如果您对此进行了改进, 随时通知我。 I've been spending far too much time trying to get this stuff all figured out, and I'd love to get some collaborative feedback. 我花了太多时间试图弄清楚所有这些东西,我很乐意得到一些合作反馈。

Angular2 Seed by Minko Gechev is probably exactly what you are looking for: Minko Gechev撰写的Angular2 Seed可能正是您要寻找的东西:

https://github.com/mgechev/angular2-seed https://github.com/mgechev/angular2-seed

It follows the official Angular2 style guide (which i think he also works on). 它遵循官方的Angular2样式指南 (我认为他也可以使用)。 So basically a pretty good starting point for training projects and probably for production projects as well. 因此,从根本上来说,这是培训项目以及生产项目的一个很好的起点。


A more lightweight seed would be from the angular2 team itself . 一个更轻量级的种子将来自angular2团队本身 But the systemjs branch is not yet updated to angular2 rc1. 但是systemjs分支尚未更新为angular2 rc1。 But updating it yourself wouldn't be so hard, since the basic setup could stay the same. 但是您自己进行更新并不难,因为基本设置可以保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在哪里可以找到angular2应用程序发行版中的版本信息? - Where can I find the version info in the dist of the angular2 application? Angular2:需要使用最新的angularCLI Webpack创建angular2文件夹结构 - Angular2 : Need to create angular2 folder structure using latest angularCLI Webpack 如何使用Angular-CLI配置/构建dist目录并在Angular2中包含图像 - How do I configure/structure the dist directory and include images in Angular2 using the Angular-CLI angular gulp-如何根据每个src文件夹拆分dist文件夹中的js文件 - angular gulp - how to split js file in dist folder according to each src folder Yeoman angular dist版本的应用程序,不限制直接文件夹访问 - Yeoman angular dist version of app, does not restrict the direct folder access 我正在尝试使用angular js将此数据绑定到HTML - I'm trying to bind this data to Html using angular js 在Angular 2中使用Angular 1库吗? - Using Angular 1 libraries in Angular 2? 我正在尝试使用Angular JS中的Javascript中的循环打印数组 - I'm trying to print an array using a loop in Javascript in Angular JS 使用angular2应用程序作为HawtIO的插件 - Using an angular2 app as a plugin for HawtIO 在Gulp中引用Angular2时出现TypeScript错误 - TypeScript errors while referencing Angular2 in Gulp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM