2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
26 var localPath = require('path');
27 var gulp = require('gulp');
28 var gulpHelpers = require('gulp-helpers');
29 var taskMaker = gulpHelpers.taskMaker(gulp);
30 var runSequence = gulpHelpers.framework('run-sequence');
31 var gulpCssUsage = require('gulp-css-usage').default;
32 var webpack = require('webpack');
33 var WebpackDevServer = require('webpack-dev-server');
34 var devWebpackConfig = require('./webpack.devConfig.js');
35 var webpackConfig = require('./webpack.config');
42 aaiOutput: dist + '/aai/',
43 assets: './resources/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}',
44 json: './src/**/*.json',
45 aaiIndex: './src/index.html',
46 scss: './resources/scss/**/*.scss',
47 aaiCss: dist + '/css',
48 war: [dist + '**/*.html', dist + '**/*.js', dist + '**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '**/*.json', 'webapp/**'],
52 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
53 taskMaker.defineTask('copy', {taskName: 'copy-aai-index.html', src: path.aaiIndex, dest: path.output, rename: 'index.html'});
55 gulp.task('copy-dev-stuff', callback => {
56 return runSequence(['copy-aai-index.html'], callback);
59 gulp.task('copy-stuff', callback => {
60 return runSequence(['copy-aai-index.html'], callback);
63 gulp.task('dev', callback => {
64 return runSequence('clean', 'copy-dev-stuff', 'webpack-dev-server', callback);
68 gulp.task('build', callback => {
69 return runSequence('clean', ['copy-stuff'], 'prod', callback);
72 gulp.task('default', ['dev']);
74 gulp.task('prod', () => {
76 return new Promise((resolve, reject)=> {
77 // configure webpack for production
78 let webpackProductionConfig = Object.create(webpackConfig);
80 for (let name in webpackProductionConfig.entry) {
81 webpackProductionConfig.entry[name] = webpackProductionConfig.entry[name].filter(path => !path.startsWith('webpack'));
84 webpackProductionConfig.cache = true;
85 webpackProductionConfig.output = {
86 path: localPath.join(__dirname, 'dist'),
87 publicPath: '/services/aai/webapp/',
90 webpackProductionConfig.resolveLoader = {
91 root: [localPath.resolve('.')],
93 'config-json-loader': 'tools/webpack/config-json-loader/index.js'
98 webpackProductionConfig.devtool = undefined;
99 webpackProductionConfig.module.preLoaders = webpackProductionConfig.module.preLoaders.filter(preLoader => preLoader.loader != 'source-map-loader');
100 webpackProductionConfig.module.loaders.forEach(loader => {
101 if (loader.loaders && loader.loaders[0] === 'style') {
102 loader.loaders = loader.loaders.map(loaderName => loaderName.replace('?sourceMap', ''));
106 webpackProductionConfig.module.loaders.push({test: /config.json$/, loaders: ['config-json-loader']});
107 webpackProductionConfig.eslint = {
108 configFile: './.eslintrc',
111 webpackProductionConfig.plugins = [
112 new webpack.DefinePlugin({
114 // This has effect on the react lib size
115 'NODE_ENV': JSON.stringify('production')
120 new webpack.optimize.DedupePlugin(),
121 new webpack.optimize.UglifyJsPlugin()
124 // run production build
125 webpack(webpackProductionConfig, function (err, stats) {
126 console.log('[webpack:build]', stats.toString());
127 if (err || stats.hasErrors()) {
128 console.log('bundleJS : Failure!!');
132 console.log('bundleJS : Done');
140 gulp.task('webpack-dev-server', () => {
141 let myConfig = Object.create(devWebpackConfig);
143 // Start a webpack-dev-server
144 let server = new WebpackDevServer(webpack(myConfig), myConfig.devServer);
145 server.listen(myConfig.devServer.port, '0.0.0.0', err => {
147 throw new Error('webpack-dev-server' + err);