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 | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 10 | |
| 11 | module.exports = { |
| 12 | module: { |
| 13 | loaders: [ |
| 14 | { |
| 15 | test: /.json$/, |
| 16 | loaders: [ |
| 17 | 'json' |
| 18 | ] |
| 19 | }, |
| 20 | { |
| 21 | test: /\.(css|scss)$/, |
| 22 | loaders: ExtractTextPlugin.extract({ |
| 23 | fallbackLoader: 'style', |
| 24 | loader: 'css?minimize!sass!postcss' |
| 25 | }) |
| 26 | }, |
| 27 | { |
| 28 | test: /\.ts$/, |
| 29 | exclude: /node_modules/, |
| 30 | loaders: [ |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 31 | 'ng-annotate', |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 32 | 'ts' |
| 33 | ] |
| 34 | }, |
| 35 | { |
| 36 | test: /.html$/, |
| 37 | loaders: [ |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 38 | 'html?' + JSON.stringify({ |
| 39 | attrs: ["img:src", "img:ng-src"] |
| 40 | }) |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 41 | ] |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 42 | }, |
| 43 | { |
| 44 | test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/, |
| 45 | loader: 'url-loader?limit=100000' |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 46 | } |
| 47 | ] |
| 48 | }, |
| 49 | plugins: [ |
| 50 | new webpack.optimize.OccurrenceOrderPlugin(), |
| 51 | new webpack.NoErrorsPlugin(), |
| 52 | new HtmlWebpackPlugin({ |
| 53 | template: conf.path.src('index.html') |
| 54 | }), |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 55 | new webpack.optimize.UglifyJsPlugin({ |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 56 | compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase |
| 57 | mangle: false // NOTE mangling was breaking the build |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 58 | }), |
| 59 | new ExtractTextPlugin('index-[contenthash].css'), |
Matteo Scandolo | 37d6509 | 2017-01-12 12:03:05 -0800 | [diff] [blame] | 60 | new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 61 | new webpack.ProvidePlugin({ |
| 62 | $: "jquery", |
| 63 | jQuery: "jquery" |
Matteo Scandolo | ad90b99 | 2017-01-12 16:16:12 -0800 | [diff] [blame] | 64 | }), |
| 65 | new BaseHrefWebpackPlugin({ |
| 66 | baseHref: '/spa/' |
Matteo Scandolo | 37d6509 | 2017-01-12 12:03:05 -0800 | [diff] [blame] | 67 | }) |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 68 | ], |
| 69 | postcss: () => [autoprefixer], |
| 70 | output: { |
| 71 | path: path.join(process.cwd(), conf.paths.dist), |
Matteo Scandolo | f4b8517 | 2017-01-11 09:56:02 -0800 | [diff] [blame] | 72 | publicPath: "/spa/", // enable apache proxying on the head node |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 73 | filename: '[name]-[hash].js' |
| 74 | }, |
| 75 | resolve: { |
| 76 | extensions: [ |
| 77 | '', |
| 78 | '.webpack.js', |
| 79 | '.web.js', |
| 80 | '.js', |
| 81 | '.ts' |
| 82 | ] |
| 83 | }, |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 84 | entry: { |
| 85 | app: `./${conf.path.src('index')}`, |
| 86 | vendor: Object.keys(pkg.dependencies) |
| 87 | }, |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 88 | ts: { |
| 89 | configFileName: 'tsconfig.json' |
| 90 | }, |
| 91 | tslint: { |
| 92 | configuration: require('../tslint.json') |
| 93 | } |
| 94 | }; |