Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -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 | d819c92 | 2016-12-02 14:06:14 -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'); |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 25 | const pkg = require('../package.json'); |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 26 | const autoprefixer = require('autoprefixer'); |
Matteo Scandolo | ad90b99 | 2017-01-12 16:16:12 -0800 | [diff] [blame] | 27 | const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 28 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 29 | const brand = process.env.BRAND || 'cord'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 30 | |
| 31 | module.exports = { |
| 32 | module: { |
| 33 | loaders: [ |
| 34 | { |
| 35 | test: /.json$/, |
| 36 | loaders: [ |
| 37 | 'json' |
| 38 | ] |
| 39 | }, |
| 40 | { |
| 41 | test: /\.(css|scss)$/, |
| 42 | loaders: ExtractTextPlugin.extract({ |
| 43 | fallbackLoader: 'style', |
Matteo Scandolo | 8b2370c | 2017-02-02 17:19:07 -0800 | [diff] [blame] | 44 | loader: 'css?minimize!resolve-url-loader!sass?sourceMap!postcss' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 45 | }) |
| 46 | }, |
| 47 | { |
| 48 | test: /\.ts$/, |
| 49 | exclude: /node_modules/, |
| 50 | loaders: [ |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 51 | 'ng-annotate', |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 52 | 'ts' |
| 53 | ] |
| 54 | }, |
| 55 | { |
| 56 | test: /.html$/, |
| 57 | loaders: [ |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 58 | 'html?' + JSON.stringify({ |
| 59 | attrs: ["img:src", "img:ng-src"] |
| 60 | }) |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 61 | ] |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 62 | }, |
| 63 | { |
| 64 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 65 | loader: 'url-loader?limit=100000' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 66 | } |
| 67 | ] |
| 68 | }, |
| 69 | plugins: [ |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 70 | new CopyWebpackPlugin([ |
Matteo Scandolo | 2ff270d | 2017-09-08 15:43:45 -0700 | [diff] [blame] | 71 | { from: `./conf/app/app.config.production.js`, to: `app.config.js` }, |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 72 | { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` }, |
| 73 | ]), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 74 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 75 | new webpack.NoErrorsPlugin(), |
| 76 | new HtmlWebpackPlugin({ |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 77 | inject: true, |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 78 | template: conf.path.src('index.html') |
| 79 | }), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 80 | new webpack.optimize.UglifyJsPlugin({ |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 81 | compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase |
| 82 | mangle: false // NOTE mangling was breaking the build |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 83 | }), |
Matteo Scandolo | 700adbf | 2017-03-15 17:06:58 -0700 | [diff] [blame] | 84 | new ExtractTextPlugin('[name].css'), |
Matteo Scandolo | 37d6509 | 2017-01-12 12:03:05 -0800 | [diff] [blame] | 85 | new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 86 | new webpack.ProvidePlugin({ |
| 87 | $: "jquery", |
| 88 | jQuery: "jquery" |
Matteo Scandolo | ad90b99 | 2017-01-12 16:16:12 -0800 | [diff] [blame] | 89 | }), |
| 90 | new BaseHrefWebpackPlugin({ |
Matteo Scandolo | 37d5606 | 2017-04-24 15:03:00 -0700 | [diff] [blame] | 91 | baseHref: '/xos/' |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 92 | }), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 93 | ], |
| 94 | postcss: () => [autoprefixer], |
| 95 | output: { |
| 96 | path: path.join(process.cwd(), conf.paths.dist), |
Matteo Scandolo | 37d5606 | 2017-04-24 15:03:00 -0700 | [diff] [blame] | 97 | publicPath: "/xos/", // enable apache proxying on the head node |
Matteo Scandolo | 700adbf | 2017-03-15 17:06:58 -0700 | [diff] [blame] | 98 | filename: '[name].js' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 99 | }, |
| 100 | resolve: { |
| 101 | extensions: [ |
| 102 | '', |
| 103 | '.webpack.js', |
| 104 | '.web.js', |
| 105 | '.js', |
| 106 | '.ts' |
Matteo Scandolo | ec521ea | 2017-03-02 11:39:41 -0800 | [diff] [blame] | 107 | ], |
| 108 | alias: { |
| 109 | "ngprogress": path.resolve(__dirname, '../node_modules/ngprogress/build/ngProgress.js') |
| 110 | } |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 111 | }, |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 112 | entry: { |
| 113 | app: `./${conf.path.src('index')}`, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 114 | vendor: Object.keys(pkg.dependencies), |
| 115 | loader: `./${conf.path.src('/app/style/imports/loader.scss')}` |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 116 | }, |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 117 | ts: { |
| 118 | configFileName: 'tsconfig.json' |
| 119 | }, |
| 120 | tslint: { |
| 121 | configuration: require('../tslint.json') |
| 122 | } |
| 123 | }; |
Matteo Scandolo | 08464e5 | 2017-01-17 13:35:27 -0800 | [diff] [blame] | 124 | |