Matteo Scandolo | c46a82d | 2017-03-24 18:37:18 -0700 | [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'); |
| 7 | const pkg = require('../package.json'); |
| 8 | const autoprefixer = require('autoprefixer'); |
| 9 | const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin; |
| 10 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 11 | const env = process.env.NODE_ENV || 'production'; |
| 12 | const brand = process.env.BRAND || 'cord'; |
| 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: [ |
| 34 | 'ng-annotate', |
| 35 | 'ts' |
| 36 | ] |
| 37 | }, |
| 38 | { |
| 39 | test: /.html$/, |
| 40 | loaders: [ |
| 41 | 'html?' + JSON.stringify({ |
| 42 | attrs: ["img:src", "img:ng-src"] |
| 43 | }) |
| 44 | ] |
| 45 | }, |
| 46 | { |
| 47 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 48 | loader: 'url-loader?limit=100000' |
| 49 | } |
| 50 | ] |
| 51 | }, |
| 52 | plugins: [ |
| 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 | ]), |
| 57 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 58 | new webpack.NoErrorsPlugin(), |
| 59 | new HtmlWebpackPlugin({ |
| 60 | inject: true, |
| 61 | template: conf.path.src('index.html') |
| 62 | }), |
| 63 | new webpack.optimize.UglifyJsPlugin({ |
| 64 | compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase |
| 65 | mangle: false // NOTE mangling was breaking the build |
| 66 | }), |
| 67 | new ExtractTextPlugin('index-[contenthash].css'), |
| 68 | new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 69 | new webpack.ProvidePlugin({ |
| 70 | $: "jquery", |
| 71 | jQuery: "jquery" |
| 72 | }), |
| 73 | new BaseHrefWebpackPlugin({ |
| 74 | baseHref: '/spa/' |
| 75 | }), |
| 76 | ], |
| 77 | postcss: () => [autoprefixer], |
| 78 | output: { |
| 79 | path: path.join(process.cwd(), conf.paths.dist), |
| 80 | publicPath: "/spa/", // enable apache proxying on the head node |
| 81 | filename: '[name].js' |
| 82 | }, |
| 83 | resolve: { |
| 84 | extensions: [ |
| 85 | '', |
| 86 | '.webpack.js', |
| 87 | '.web.js', |
| 88 | '.js', |
| 89 | '.ts' |
| 90 | ] |
| 91 | }, |
| 92 | entry: { |
| 93 | app: `./${conf.path.src('index')}`, |
| 94 | vendor: Object.keys(pkg.dependencies) |
| 95 | }, |
| 96 | ts: { |
| 97 | configFileName: 'tsconfig.json' |
| 98 | }, |
| 99 | tslint: { |
| 100 | configuration: require('../tslint.json') |
| 101 | } |
| 102 | }; |
| 103 | |