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', |
| 27 | loader: 'css?minimize!sass!postcss' |
| 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 | }), |
| 67 | new ExtractTextPlugin('index-[contenthash].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({ |
| 74 | baseHref: '/spa/' |
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 | f4b8517 | 2017-01-11 09:56:02 -0800 | [diff] [blame] | 80 | publicPath: "/spa/", // enable apache proxying on the head node |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 81 | filename: '[name]-[hash].js' |
| 82 | }, |
| 83 | resolve: { |
| 84 | extensions: [ |
| 85 | '', |
| 86 | '.webpack.js', |
| 87 | '.web.js', |
| 88 | '.js', |
| 89 | '.ts' |
| 90 | ] |
| 91 | }, |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 92 | entry: { |
| 93 | app: `./${conf.path.src('index')}`, |
| 94 | vendor: Object.keys(pkg.dependencies) |
| 95 | }, |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 96 | ts: { |
| 97 | configFileName: 'tsconfig.json' |
| 98 | }, |
| 99 | tslint: { |
| 100 | configuration: require('../tslint.json') |
| 101 | } |
| 102 | }; |
Matteo Scandolo | 08464e5 | 2017-01-17 13:35:27 -0800 | [diff] [blame] | 103 | |