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