blob: e4cf6fb96359d658b50bc91f36d9fbdfc96b6369 [file] [log] [blame]
Matteo Scandolod819c922016-12-02 14:06:14 -08001const webpack = require('webpack');
2const conf = require('./gulp.conf');
3const path = require('path');
4
5const HtmlWebpackPlugin = require('html-webpack-plugin');
6const ExtractTextPlugin = require('extract-text-webpack-plugin');
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08007const pkg = require('../package.json');
Matteo Scandolod819c922016-12-02 14:06:14 -08008const autoprefixer = require('autoprefixer');
Matteo Scandoload90b992017-01-12 16:16:12 -08009const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin;
Matteo Scandolo828d1e82017-01-17 14:49:38 -080010const CopyWebpackPlugin = require('copy-webpack-plugin');
11const env = process.env.NODE_ENV || 'production';
12const brand = process.env.BRAND || 'cord';
Matteo Scandolod819c922016-12-02 14:06:14 -080013
14module.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 Scandolo8b2370c2017-02-02 17:19:07 -080027 loader: 'css?minimize!resolve-url-loader!sass?sourceMap!postcss'
Matteo Scandolod819c922016-12-02 14:06:14 -080028 })
29 },
30 {
31 test: /\.ts$/,
32 exclude: /node_modules/,
33 loaders: [
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080034 'ng-annotate',
Matteo Scandolod819c922016-12-02 14:06:14 -080035 'ts'
36 ]
37 },
38 {
39 test: /.html$/,
40 loaders: [
Matteo Scandolod62ea792016-12-22 14:02:28 -080041 'html?' + JSON.stringify({
42 attrs: ["img:src", "img:ng-src"]
43 })
Matteo Scandolod819c922016-12-02 14:06:14 -080044 ]
Matteo Scandolo266907e2016-12-20 13:41:42 -080045 },
46 {
47 test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/,
48 loader: 'url-loader?limit=100000'
Matteo Scandolod819c922016-12-02 14:06:14 -080049 }
50 ]
51 },
52 plugins: [
Matteo Scandolo828d1e82017-01-17 14:49:38 -080053 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 Scandolod819c922016-12-02 14:06:14 -080057 new webpack.optimize.OccurrenceOrderPlugin(),
58 new webpack.NoErrorsPlugin(),
59 new HtmlWebpackPlugin({
Matteo Scandolo828d1e82017-01-17 14:49:38 -080060 inject: true,
Matteo Scandolod819c922016-12-02 14:06:14 -080061 template: conf.path.src('index.html')
62 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080063 new webpack.optimize.UglifyJsPlugin({
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080064 compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase
65 mangle: false // NOTE mangling was breaking the build
Matteo Scandolod819c922016-12-02 14:06:14 -080066 }),
67 new ExtractTextPlugin('index-[contenthash].css'),
Matteo Scandolo37d65092017-01-12 12:03:05 -080068 new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
69 new webpack.ProvidePlugin({
70 $: "jquery",
71 jQuery: "jquery"
Matteo Scandoload90b992017-01-12 16:16:12 -080072 }),
73 new BaseHrefWebpackPlugin({
74 baseHref: '/spa/'
Matteo Scandolo828d1e82017-01-17 14:49:38 -080075 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080076 ],
77 postcss: () => [autoprefixer],
78 output: {
79 path: path.join(process.cwd(), conf.paths.dist),
Matteo Scandolof4b85172017-01-11 09:56:02 -080080 publicPath: "/spa/", // enable apache proxying on the head node
Matteo Scandolod819c922016-12-02 14:06:14 -080081 filename: '[name]-[hash].js'
82 },
83 resolve: {
84 extensions: [
85 '',
86 '.webpack.js',
87 '.web.js',
88 '.js',
89 '.ts'
Matteo Scandoloec521ea2017-03-02 11:39:41 -080090 ],
91 alias: {
92 "ngprogress": path.resolve(__dirname, '../node_modules/ngprogress/build/ngProgress.js')
93 }
Matteo Scandolod819c922016-12-02 14:06:14 -080094 },
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080095 entry: {
96 app: `./${conf.path.src('index')}`,
Matteo Scandolo042ea632017-03-01 19:02:34 -080097 vendor: Object.keys(pkg.dependencies),
98 loader: `./${conf.path.src('/app/style/imports/loader.scss')}`
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080099 },
Matteo Scandolod819c922016-12-02 14:06:14 -0800100 ts: {
101 configFileName: 'tsconfig.json'
102 },
103 tslint: {
104 configuration: require('../tslint.json')
105 }
106};
Matteo Scandolo08464e52017-01-17 13:35:27 -0800107