blob: ba798164f164065a7013a8eebd001e177d7b54fa [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolod819c922016-12-02 14:06:14 -080019const webpack = require('webpack');
20const conf = require('./gulp.conf');
21const path = require('path');
22
23const HtmlWebpackPlugin = require('html-webpack-plugin');
24const ExtractTextPlugin = require('extract-text-webpack-plugin');
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080025const pkg = require('../package.json');
Matteo Scandolod819c922016-12-02 14:06:14 -080026const autoprefixer = require('autoprefixer');
Matteo Scandoload90b992017-01-12 16:16:12 -080027const BaseHrefWebpackPlugin = require('base-href-webpack-plugin').BaseHrefWebpackPlugin;
Matteo Scandolo828d1e82017-01-17 14:49:38 -080028const CopyWebpackPlugin = require('copy-webpack-plugin');
Matteo Scandolo828d1e82017-01-17 14:49:38 -080029const brand = process.env.BRAND || 'cord';
Matteo Scandolod819c922016-12-02 14:06:14 -080030
31module.exports = {
32 module: {
33 loaders: [
34 {
35 test: /.json$/,
36 loaders: [
37 'json'
38 ]
39 },
40 {
41 test: /\.(css|scss)$/,
42 loaders: ExtractTextPlugin.extract({
43 fallbackLoader: 'style',
Matteo Scandolo8b2370c2017-02-02 17:19:07 -080044 loader: 'css?minimize!resolve-url-loader!sass?sourceMap!postcss'
Matteo Scandolod819c922016-12-02 14:06:14 -080045 })
46 },
47 {
48 test: /\.ts$/,
49 exclude: /node_modules/,
50 loaders: [
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080051 'ng-annotate',
Matteo Scandolod819c922016-12-02 14:06:14 -080052 'ts'
53 ]
54 },
55 {
56 test: /.html$/,
57 loaders: [
Matteo Scandolod62ea792016-12-22 14:02:28 -080058 'html?' + JSON.stringify({
59 attrs: ["img:src", "img:ng-src"]
60 })
Matteo Scandolod819c922016-12-02 14:06:14 -080061 ]
Matteo Scandolo266907e2016-12-20 13:41:42 -080062 },
63 {
64 test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/,
65 loader: 'url-loader?limit=100000'
Matteo Scandolod819c922016-12-02 14:06:14 -080066 }
67 ]
68 },
69 plugins: [
Matteo Scandolo828d1e82017-01-17 14:49:38 -080070 new CopyWebpackPlugin([
Matteo Scandolo2ff270d2017-09-08 15:43:45 -070071 { from: `./conf/app/app.config.production.js`, to: `app.config.js` },
Matteo Scandolo828d1e82017-01-17 14:49:38 -080072 { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` },
73 ]),
Matteo Scandolod819c922016-12-02 14:06:14 -080074 new webpack.optimize.OccurrenceOrderPlugin(),
75 new webpack.NoErrorsPlugin(),
76 new HtmlWebpackPlugin({
Matteo Scandolo828d1e82017-01-17 14:49:38 -080077 inject: true,
Matteo Scandolod819c922016-12-02 14:06:14 -080078 template: conf.path.src('index.html')
79 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080080 new webpack.optimize.UglifyJsPlugin({
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080081 compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase
82 mangle: false // NOTE mangling was breaking the build
Matteo Scandolod819c922016-12-02 14:06:14 -080083 }),
Matteo Scandolo700adbf2017-03-15 17:06:58 -070084 new ExtractTextPlugin('[name].css'),
Matteo Scandolo37d65092017-01-12 12:03:05 -080085 new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
86 new webpack.ProvidePlugin({
87 $: "jquery",
88 jQuery: "jquery"
Matteo Scandoload90b992017-01-12 16:16:12 -080089 }),
90 new BaseHrefWebpackPlugin({
Matteo Scandolo37d56062017-04-24 15:03:00 -070091 baseHref: '/xos/'
Matteo Scandolo828d1e82017-01-17 14:49:38 -080092 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080093 ],
94 postcss: () => [autoprefixer],
95 output: {
96 path: path.join(process.cwd(), conf.paths.dist),
Matteo Scandolo37d56062017-04-24 15:03:00 -070097 publicPath: "/xos/", // enable apache proxying on the head node
Matteo Scandolo700adbf2017-03-15 17:06:58 -070098 filename: '[name].js'
Matteo Scandolod819c922016-12-02 14:06:14 -080099 },
100 resolve: {
101 extensions: [
102 '',
103 '.webpack.js',
104 '.web.js',
105 '.js',
106 '.ts'
Matteo Scandoloec521ea2017-03-02 11:39:41 -0800107 ],
108 alias: {
109 "ngprogress": path.resolve(__dirname, '../node_modules/ngprogress/build/ngProgress.js')
110 }
Matteo Scandolod819c922016-12-02 14:06:14 -0800111 },
Matteo Scandolof6acdbe2016-12-13 10:29:37 -0800112 entry: {
113 app: `./${conf.path.src('index')}`,
Matteo Scandolo042ea632017-03-01 19:02:34 -0800114 vendor: Object.keys(pkg.dependencies),
115 loader: `./${conf.path.src('/app/style/imports/loader.scss')}`
Matteo Scandolof6acdbe2016-12-13 10:29:37 -0800116 },
Matteo Scandolod819c922016-12-02 14:06:14 -0800117 ts: {
118 configFileName: 'tsconfig.json'
119 },
120 tslint: {
121 configuration: require('../tslint.json')
122 }
123};
Matteo Scandolo08464e52017-01-17 13:35:27 -0800124