2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
28 var localPath = require('path');
29 var gulp = require('gulp');
30 var gulpHelpers = require('gulp-helpers');
31 var taskMaker = gulpHelpers.taskMaker(gulp);
32 var runSequence = gulpHelpers.framework('run-sequence');
33 var gulpCssUsage = require('gulp-css-usage').default;
34 var webpack = require('webpack');
35 var WebpackDevServer = require('webpack-dev-server');
36 var devWebpackConfig = require('./webpack.devConfig.js');
37 var webpackConfig = require('./webpack.config');
44 aaiOutput: dist + '/aai/',
45 assets: './resources/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}',
46 json: './src/**/*.json',
47 aaiIndex: './src/index.html',
48 scss: './resources/scss/**/*.scss',
49 aaiCss: dist + '/css',
50 war: [dist + '**/*.html', dist + '**/*.js', dist + '**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '**/*.json', 'webapp/**'],
54 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
55 taskMaker.defineTask('copy', {taskName: 'copy-aai-index.html', src: path.aaiIndex, dest: path.output, rename: 'index.html'});
57 gulp.task('copy-dev-stuff', callback => {
58 return runSequence(['copy-aai-index.html'], callback);
61 gulp.task('copy-stuff', callback => {
62 return runSequence(['copy-aai-index.html'], callback);
65 gulp.task('dev', callback => {
66 return runSequence('clean', 'copy-dev-stuff', 'webpack-dev-server', callback);
70 gulp.task('build', callback => {
71 return runSequence('clean', ['copy-stuff'], 'prod', callback);
74 gulp.task('default', ['dev']);
76 gulp.task('prod', () => {
78 return new Promise((resolve, reject)=> {
79 // configure webpack for production
80 let webpackProductionConfig = Object.create(webpackConfig);
82 for (let name in webpackProductionConfig.entry) {
83 webpackProductionConfig.entry[name] = webpackProductionConfig.entry[name].filter(path => !path.startsWith('webpack'));
86 webpackProductionConfig.cache = true;
87 webpackProductionConfig.output = {
88 path: localPath.join(__dirname, 'dist'),
89 publicPath: '/services/aai/webapp/',
92 webpackProductionConfig.resolveLoader = {
93 root: [localPath.resolve('.')],
95 'config-json-loader': 'tools/webpack/config-json-loader/index.js'
100 webpackProductionConfig.devtool = undefined;
101 webpackProductionConfig.module.preLoaders = webpackProductionConfig.module.preLoaders.filter(preLoader => preLoader.loader != 'source-map-loader');
102 webpackProductionConfig.module.loaders.forEach(loader => {
103 if (loader.loaders && loader.loaders[0] === 'style') {
104 loader.loaders = loader.loaders.map(loaderName => loaderName.replace('?sourceMap', ''));
108 webpackProductionConfig.module.loaders.push({test: /config.json$/, loaders: ['config-json-loader']});
109 webpackProductionConfig.eslint = {
110 configFile: './.eslintrc',
113 webpackProductionConfig.plugins = [
114 new webpack.DefinePlugin({
116 // This has effect on the react lib size
117 'NODE_ENV': JSON.stringify('production')
122 new webpack.optimize.DedupePlugin(),
123 new webpack.optimize.UglifyJsPlugin()
126 // run production build
127 webpack(webpackProductionConfig, function (err, stats) {
128 console.log('[webpack:build]', stats.toString());
129 if (err || stats.hasErrors()) {
130 console.log('bundleJS : Failure!!');
134 console.log('bundleJS : Done');
142 gulp.task('webpack-dev-server', () => {
143 let myConfig = Object.create(devWebpackConfig);
145 // Start a webpack-dev-server
146 let server = new WebpackDevServer(webpack(myConfig), myConfig.devServer);
147 server.listen(myConfig.devServer.port, '0.0.0.0', err => {
149 throw new Error('webpack-dev-server' + err);