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