Max Chu | 6a4bb65 | 2017-09-29 17:15:56 -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 | |
| 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'); |
| 25 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 26 | const env = process.env.NODE_ENV || 'production'; |
| 27 | const brand = process.env.BRAND || 'cord'; |
| 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)$/, |
| 48 | loaders: [ |
| 49 | 'style', |
| 50 | 'css', |
| 51 | 'sass', |
| 52 | 'postcss' |
| 53 | ] |
| 54 | }, |
| 55 | { |
| 56 | test: /\.ts$/, |
| 57 | exclude: /node_modules/, |
| 58 | loaders: [ |
| 59 | 'ng-annotate', |
| 60 | 'ts' |
| 61 | ] |
| 62 | }, |
| 63 | { |
| 64 | test: /.html$/, |
| 65 | loaders: [ |
| 66 | 'html?' + JSON.stringify({ |
| 67 | attrs: ["img:src", "img:ng-src"] |
| 68 | }) |
| 69 | ] |
| 70 | }, |
| 71 | { |
| 72 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 73 | loader: 'url-loader?limit=100000' |
| 74 | } |
| 75 | ] |
| 76 | }, |
| 77 | plugins: [ |
| 78 | new CopyWebpackPlugin([ |
| 79 | { from: `./conf/app/app.config.${env}.js`, to: `app.config.js` }, |
| 80 | { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` }, |
| 81 | ]), |
| 82 | new webpack.IgnorePlugin(/\.\/locale$/), |
| 83 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 84 | new webpack.NoErrorsPlugin(), |
| 85 | new HtmlWebpackPlugin({ |
| 86 | template: conf.path.src('index.html') |
| 87 | }) |
| 88 | ], |
| 89 | postcss: () => [autoprefixer], |
| 90 | debug: true, |
| 91 | devtool: 'source-map', |
| 92 | output: { |
| 93 | path: path.join(process.cwd(), conf.paths.tmp), |
| 94 | filename: 'index.js' |
| 95 | }, |
| 96 | resolve: { |
| 97 | extensions: [ |
| 98 | '', |
| 99 | '.webpack.js', |
| 100 | '.web.js', |
| 101 | '.js', |
| 102 | '.ts' |
| 103 | ] |
| 104 | }, |
| 105 | entry: `./${conf.path.src('index')}`, |
| 106 | ts: { |
| 107 | configFileName: 'tsconfig.json' |
| 108 | }, |
| 109 | tslint: { |
| 110 | configuration: require('../tslint.json') |
| 111 | }, |
| 112 | stats: { |
| 113 | colors: true, |
| 114 | modules: true, |
| 115 | reasons: true, |
| 116 | errorDetails: true |
| 117 | } |
| 118 | }; |