blob: ef3f46907b4e42bee2bcff51e30491a5a1844fc4 [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');
29const env = process.env.NODE_ENV || 'production';
30const brand = process.env.BRAND || 'cord';
Matteo Scandolod819c922016-12-02 14:06:14 -080031
32module.exports = {
33 module: {
34 loaders: [
35 {
36 test: /.json$/,
37 loaders: [
38 'json'
39 ]
40 },
41 {
42 test: /\.(css|scss)$/,
43 loaders: ExtractTextPlugin.extract({
44 fallbackLoader: 'style',
Matteo Scandolo8b2370c2017-02-02 17:19:07 -080045 loader: 'css?minimize!resolve-url-loader!sass?sourceMap!postcss'
Matteo Scandolod819c922016-12-02 14:06:14 -080046 })
47 },
48 {
49 test: /\.ts$/,
50 exclude: /node_modules/,
51 loaders: [
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080052 'ng-annotate',
Matteo Scandolod819c922016-12-02 14:06:14 -080053 'ts'
54 ]
55 },
56 {
57 test: /.html$/,
58 loaders: [
Matteo Scandolod62ea792016-12-22 14:02:28 -080059 'html?' + JSON.stringify({
60 attrs: ["img:src", "img:ng-src"]
61 })
Matteo Scandolod819c922016-12-02 14:06:14 -080062 ]
Matteo Scandolo266907e2016-12-20 13:41:42 -080063 },
64 {
65 test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/,
66 loader: 'url-loader?limit=100000'
Matteo Scandolod819c922016-12-02 14:06:14 -080067 }
68 ]
69 },
70 plugins: [
Matteo Scandolo828d1e82017-01-17 14:49:38 -080071 new CopyWebpackPlugin([
72 { from: `./conf/app/app.config.${env}.js`, to: `app.config.js` },
73 { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` },
74 ]),
Matteo Scandolod819c922016-12-02 14:06:14 -080075 new webpack.optimize.OccurrenceOrderPlugin(),
76 new webpack.NoErrorsPlugin(),
77 new HtmlWebpackPlugin({
Matteo Scandolo828d1e82017-01-17 14:49:38 -080078 inject: true,
Matteo Scandolod819c922016-12-02 14:06:14 -080079 template: conf.path.src('index.html')
80 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080081 new webpack.optimize.UglifyJsPlugin({
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080082 compress: {unused: true, dead_code: true, warnings: false}, // eslint-disable-line camelcase
83 mangle: false // NOTE mangling was breaking the build
Matteo Scandolod819c922016-12-02 14:06:14 -080084 }),
Matteo Scandolo700adbf2017-03-15 17:06:58 -070085 new ExtractTextPlugin('[name].css'),
Matteo Scandolo37d65092017-01-12 12:03:05 -080086 new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
87 new webpack.ProvidePlugin({
88 $: "jquery",
89 jQuery: "jquery"
Matteo Scandoload90b992017-01-12 16:16:12 -080090 }),
91 new BaseHrefWebpackPlugin({
Matteo Scandolo37d56062017-04-24 15:03:00 -070092 baseHref: '/xos/'
Matteo Scandolo828d1e82017-01-17 14:49:38 -080093 }),
Matteo Scandolod819c922016-12-02 14:06:14 -080094 ],
95 postcss: () => [autoprefixer],
96 output: {
97 path: path.join(process.cwd(), conf.paths.dist),
Matteo Scandolo37d56062017-04-24 15:03:00 -070098 publicPath: "/xos/", // enable apache proxying on the head node
Matteo Scandolo700adbf2017-03-15 17:06:58 -070099 filename: '[name].js'
Matteo Scandolod819c922016-12-02 14:06:14 -0800100 },
101 resolve: {
102 extensions: [
103 '',
104 '.webpack.js',
105 '.web.js',
106 '.js',
107 '.ts'
Matteo Scandoloec521ea2017-03-02 11:39:41 -0800108 ],
109 alias: {
110 "ngprogress": path.resolve(__dirname, '../node_modules/ngprogress/build/ngProgress.js')
111 }
Matteo Scandolod819c922016-12-02 14:06:14 -0800112 },
Matteo Scandolof6acdbe2016-12-13 10:29:37 -0800113 entry: {
114 app: `./${conf.path.src('index')}`,
Matteo Scandolo042ea632017-03-01 19:02:34 -0800115 vendor: Object.keys(pkg.dependencies),
116 loader: `./${conf.path.src('/app/style/imports/loader.scss')}`
Matteo Scandolof6acdbe2016-12-13 10:29:37 -0800117 },
Matteo Scandolod819c922016-12-02 14:06:14 -0800118 ts: {
119 configFileName: 'tsconfig.json'
120 },
121 tslint: {
122 configuration: require('../tslint.json')
123 }
124};
Matteo Scandolo08464e52017-01-17 13:35:27 -0800125