Matteo Scandolo | a86e0a1 | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 19 | const webpack = require('webpack'); |
| 20 | const conf = require('./gulp.conf'); |
| 21 | const path = require('path'); |
| 22 | |
| 23 | const HtmlWebpackPlugin = require('html-webpack-plugin'); |
| 24 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 25 | const pkg = require('../package.json'); |
| 26 | const autoprefixer = require('autoprefixer'); |
| 27 | const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin; |
| 28 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 29 | const env = process.env.NODE_ENV || 'production'; |
| 30 | const brand = process.env.BRAND || 'cord'; |
| 31 | |
| 32 | module.exports = { |
| 33 | module: { |
| 34 | loaders: [ |
| 35 | { |
| 36 | test: /.json$/, |
| 37 | loaders: [ |
| 38 | 'json' |
| 39 | ] |
| 40 | }, |
| 41 | { |
| 42 | test: /\.(css|scss)$/, |
| 43 | loaders: ExtractTextPlugin.extract({ |
| 44 | fallbackLoader: 'style', |
| 45 | loader: 'css?minimize!sass!postcss' |
| 46 | }) |
| 47 | }, |
| 48 | { |
| 49 | test: /\.ts$/, |
| 50 | exclude: /node_modules/, |
| 51 | loaders: [ |
| 52 | 'ng-annotate', |
| 53 | 'ts' |
| 54 | ] |
| 55 | }, |
| 56 | { |
| 57 | test: /.html$/, |
| 58 | loaders: [ |
| 59 | 'html?' + JSON.stringify({ |
| 60 | attrs: ["img:src", "img:ng-src"] |
| 61 | }) |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 66 | loader: 'url-loader?limit=100000' |
| 67 | } |
| 68 | ] |
| 69 | }, |
| 70 | plugins: [ |
| 71 | new CopyWebpackPlugin([ |
| 72 | { from: `./conf/app/app.config.${env}.js`, to: `app.config.js` }, |
| 73 | { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` }, |
| 74 | ]), |
| 75 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 76 | new webpack.NoErrorsPlugin(), |
| 77 | new HtmlWebpackPlugin({ |
| 78 | inject: true, |
| 79 | template: conf.path.src('index.html') |
| 80 | }), |
| 81 | new webpack.optimize.UglifyJsPlugin({ |
| 82 | compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase |
| 83 | mangle: false // NOTE mangling was breaking the build |
| 84 | }), |
| 85 | new ExtractTextPlugin('index-[contenthash].css'), |
| 86 | new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 87 | new webpack.ProvidePlugin({ |
| 88 | $: "jquery", |
| 89 | jQuery: "jquery" |
| 90 | }), |
| 91 | new BaseHrefWebpackPlugin({ |
| 92 | baseHref: '/spa/' |
| 93 | }), |
| 94 | ], |
| 95 | postcss: () => [autoprefixer], |
| 96 | output: { |
| 97 | path: path.join(process.cwd(), conf.paths.dist), |
| 98 | publicPath: "/spa/", // enable apache proxying on the head node |
| 99 | filename: '[name].js' |
| 100 | }, |
| 101 | resolve: { |
| 102 | extensions: [ |
| 103 | '', |
| 104 | '.webpack.js', |
| 105 | '.web.js', |
| 106 | '.js', |
| 107 | '.ts' |
Matteo Scandolo | cd2caa7 | 2017-09-28 14:19:21 -0700 | [diff] [blame^] | 108 | ], |
| 109 | alias: { |
| 110 | "ngprogress": path.resolve(__dirname, '../node_modules/ngprogress/build/ngProgress.js') |
| 111 | } |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 112 | }, |
| 113 | entry: { |
| 114 | app: `./${conf.path.src('index')}`, |
| 115 | vendor: Object.keys(pkg.dependencies) |
| 116 | }, |
| 117 | ts: { |
| 118 | configFileName: 'tsconfig.json' |
| 119 | }, |
| 120 | tslint: { |
| 121 | configuration: require('../tslint.json') |
| 122 | } |
| 123 | }; |
| 124 | |