1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| 'use strict';
var gulp = require('gulp'), tsc = require('gulp-typescript'), inject = require('gulp-inject'), tsProject = tsc.createProject('tsconfig.json'), webpack = require('webpack'), gulpWebpack = require('webpack-stream'), ngAnnotatePlugin = require('ng-annotate-webpack-plugin'), path = require('path');
gulp.task('compile-ts', function () { var sourceTsFiles = ['./app/src/**/*.ts', //path to typescript files './app/typings/**/*.ts']; //reference to library .d.ts files
var tsResult = gulp.src(sourceTsFiles) .pipe(tsc(tsProject));
tsResult.dts.pipe(gulp.dest('./app/dist')); return tsResult.js.pipe(gulp.dest('./app/dist')); });
gulp.task('gen-ts-refs', function () { var target = gulp.src('./app/src/app.d.ts'); var sources = gulp.src(['./app/src/**/*.ts'], { read: false }); return target.pipe(inject(sources, { starttag: '//{', endtag: '//}', transform: function (filepath) { if (filepath.indexOf('index') > -1) { return; } if (filepath.indexOf('app.d.ts') > -1) { return; } return '/// <reference path="../..' + filepath + '" />'; } })).pipe(gulp.dest('./app/src/')); });
gulp.task('watch', function () { gulp.watch(['./app/src/**/*.ts'], ['webpack']); });
gulp.task('webpack', ['compile-ts'], function () { return gulp.src('./app/dist/app.js') .pipe(gulpWebpack({ entry: { bundled: './app/dist/app.js', commands: './app/dist/libs.js' }, output: { filename: '[name].js', }, resolve: { // this tells Webpack where actually to find lodash because you'll need it in the ProvidePlugin alias: { lodash: path.resolve(__dirname, './node_modules/lodash'), angular: path.resolve(__dirname, './node_modules/angular') }, extensions: ['', '.js'] }, module: { loaders: [ { test: /[\/]angular\.js$/, loader: "exports?angular" } ] }, plugins: [ new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/), // this tells Webpack to provide the "_" variable globally in all your app files as lodash. new webpack.ProvidePlugin({ _: "lodash", }), new ngAnnotatePlugin({ add: true }) // new webpack.optimize.CommonsChunkPlugin('common.js'), //new webpack.optimize.UglifyJsPlugin({ // compress: { // warnings: false // }, // output: { comments: false } //})
] })) .pipe(gulp.dest('./Scripts')); })
gulp.task('default', ['watch']);
|