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