Max Chu | 3ca3e20 | 2017-09-14 10:33:09 -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 ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 25 | const pkg = require('../package.json'); |
| 26 | const autoprefixer = require('autoprefixer'); |
| 27 | const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin; |
| 28 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 29 | const env = process.env.NODE_ENV || 'production'; |
| 30 | const brand = process.env.BRAND || 'cord'; |
| 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', |
| 45 | loader: 'css?minimize!sass!postcss' |
| 46 | }) |
| 47 | }, |
| 48 | { |
| 49 | test: /\.ts$/, |
| 50 | exclude: /node_modules/, |
| 51 | loaders: [ |
| 52 | 'ng-annotate', |
| 53 | 'ts' |
| 54 | ] |
| 55 | }, |
| 56 | { |
| 57 | test: /.html$/, |
| 58 | loaders: [ |
| 59 | 'html?' + JSON.stringify({ |
| 60 | attrs: ["img:src", "img:ng-src"] |
| 61 | }) |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 66 | loader: 'url-loader?limit=100000' |
| 67 | } |
| 68 | ] |
| 69 | }, |
| 70 | plugins: [ |
| 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 | ]), |
| 75 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 76 | new webpack.NoErrorsPlugin(), |
| 77 | new HtmlWebpackPlugin({ |
| 78 | inject: true, |
| 79 | template: conf.path.src('index.html') |
| 80 | }), |
| 81 | new webpack.optimize.UglifyJsPlugin({ |
| 82 | compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase |
| 83 | mangle: false // NOTE mangling was breaking the build |
| 84 | }), |
| 85 | new ExtractTextPlugin('index-[contenthash].css'), |
| 86 | new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 87 | new webpack.ProvidePlugin({ |
| 88 | $: "jquery", |
| 89 | jQuery: "jquery" |
| 90 | }), |
| 91 | new BaseHrefWebpackPlugin({ |
| 92 | baseHref: '/spa/' |
| 93 | }), |
| 94 | ], |
| 95 | postcss: () => [autoprefixer], |
| 96 | output: { |
| 97 | path: path.join(process.cwd(), conf.paths.dist), |
| 98 | publicPath: "/xos/", // enable apache proxying on the head node |
| 99 | filename: '[name].js' |
| 100 | }, |
| 101 | resolve: { |
| 102 | extensions: [ |
| 103 | '', |
| 104 | '.webpack.js', |
| 105 | '.web.js', |
| 106 | '.js', |
| 107 | '.ts' |
| 108 | ] |
| 109 | }, |
| 110 | entry: { |
| 111 | app: `./${conf.path.src('index')}`, |
| 112 | vendor: Object.keys(pkg.dependencies) |
| 113 | }, |
| 114 | ts: { |
| 115 | configFileName: 'tsconfig.json' |
| 116 | }, |
| 117 | tslint: { |
| 118 | configuration: require('../tslint.json') |
| 119 | } |
| 120 | }; |
| 121 | |