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