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 autoprefixer = require('autoprefixer'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 25 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 26 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 27 | const brand = process.env.BRAND || 'cord'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 28 | |
| 29 | module.exports = { |
| 30 | module: { |
| 31 | preLoaders: [ |
| 32 | { |
| 33 | test: /\.ts$/, |
| 34 | exclude: /node_modules/, |
| 35 | loader: 'tslint' |
| 36 | } |
| 37 | ], |
| 38 | |
| 39 | loaders: [ |
| 40 | { |
| 41 | test: /.json$/, |
| 42 | loaders: [ |
| 43 | 'json' |
| 44 | ] |
| 45 | }, |
| 46 | { |
| 47 | test: /\.(css|scss)$/, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 48 | loaders: ExtractTextPlugin.extract({ |
| 49 | fallbackLoader: 'style', |
| 50 | loader: [ |
| 51 | 'css', |
| 52 | 'resolve-url-loader', |
| 53 | 'sass?sourceMap', |
| 54 | 'postcss' |
| 55 | ] |
| 56 | }) |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 57 | }, |
| 58 | { |
| 59 | test: /\.ts$/, |
| 60 | exclude: /node_modules/, |
| 61 | loaders: [ |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 62 | 'ng-annotate', |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 63 | 'ts' |
| 64 | ] |
| 65 | }, |
| 66 | { |
| 67 | test: /.html$/, |
| 68 | loaders: [ |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 69 | 'html?' + JSON.stringify({ |
| 70 | attrs: ["img:src", "img:ng-src"] |
| 71 | }) |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 72 | ] |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 73 | }, |
| 74 | { |
| 75 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 76 | loader: 'url-loader?limit=100000' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 77 | } |
| 78 | ] |
| 79 | }, |
| 80 | plugins: [ |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 81 | new CopyWebpackPlugin([ |
Matteo Scandolo | 2ff270d | 2017-09-08 15:43:45 -0700 | [diff] [blame] | 82 | { from: `./conf/app/app.config.production.js`, to: `app.config.js` }, |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 83 | { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` }, |
| 84 | ]), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 85 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 86 | new webpack.NoErrorsPlugin(), |
| 87 | new HtmlWebpackPlugin({ |
| 88 | template: conf.path.src('index.html') |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 89 | }), |
| 90 | new ExtractTextPlugin('index-[contenthash].css'), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 91 | ], |
| 92 | postcss: () => [autoprefixer], |
| 93 | debug: true, |
| 94 | devtool: 'source-map', |
| 95 | output: { |
| 96 | path: path.join(process.cwd(), conf.paths.tmp), |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 97 | filename: '[name].js' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 98 | }, |
| 99 | resolve: { |
| 100 | extensions: [ |
| 101 | '', |
| 102 | '.webpack.js', |
| 103 | '.web.js', |
| 104 | '.js', |
| 105 | '.ts' |
| 106 | ] |
| 107 | }, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 108 | entry: { |
Matteo Scandolo | 520a8a1 | 2017-03-10 17:31:37 -0800 | [diff] [blame] | 109 | index: `./${conf.path.src('index')}`, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 110 | loader: `./${conf.path.src('/app/style/imports/loader.scss')}` |
| 111 | }, |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 112 | ts: { |
| 113 | configFileName: 'tsconfig.json' |
| 114 | }, |
| 115 | tslint: { |
| 116 | configuration: require('../tslint.json') |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 117 | }, |
| 118 | stats: { |
| 119 | colors: true, |
| 120 | modules: true, |
| 121 | reasons: true, |
| 122 | errorDetails: true |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 123 | } |
| 124 | }; |