blob: 6f21642c3d82b26071e62e5e0d0c6ee714fd63d8 [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 autoprefixer = require('autoprefixer');
Matteo Scandolo828d1e82017-01-17 14:49:38 -080025const CopyWebpackPlugin = require('copy-webpack-plugin');
Matteo Scandolo042ea632017-03-01 19:02:34 -080026const ExtractTextPlugin = require('extract-text-webpack-plugin');
Matteo Scandolo828d1e82017-01-17 14:49:38 -080027const env = process.env.NODE_ENV || 'production';
28const brand = process.env.BRAND || 'cord';
Matteo Scandolod819c922016-12-02 14:06:14 -080029
30module.exports = {
31 module: {
32 preLoaders: [
33 {
34 test: /\.ts$/,
35 exclude: /node_modules/,
36 loader: 'tslint'
37 }
38 ],
39
40 loaders: [
41 {
42 test: /.json$/,
43 loaders: [
44 'json'
45 ]
46 },
47 {
48 test: /\.(css|scss)$/,
Matteo Scandolo042ea632017-03-01 19:02:34 -080049 loaders: ExtractTextPlugin.extract({
50 fallbackLoader: 'style',
51 loader: [
52 'css',
53 'resolve-url-loader',
54 'sass?sourceMap',
55 'postcss'
56 ]
57 })
Matteo Scandolod819c922016-12-02 14:06:14 -080058 },
59 {
60 test: /\.ts$/,
61 exclude: /node_modules/,
62 loaders: [
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080063 'ng-annotate',
Matteo Scandolod819c922016-12-02 14:06:14 -080064 'ts'
65 ]
66 },
67 {
68 test: /.html$/,
69 loaders: [
Matteo Scandolo99fface2016-12-21 15:37:23 -080070 'html?' + JSON.stringify({
71 attrs: ["img:src", "img:ng-src"]
72 })
Matteo Scandolod819c922016-12-02 14:06:14 -080073 ]
Matteo Scandolo266907e2016-12-20 13:41:42 -080074 },
75 {
76 test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/,
77 loader: 'url-loader?limit=100000'
Matteo Scandolod819c922016-12-02 14:06:14 -080078 }
79 ]
80 },
81 plugins: [
Matteo Scandolo828d1e82017-01-17 14:49:38 -080082 new CopyWebpackPlugin([
83 { from: `./conf/app/app.config.${env}.js`, to: `app.config.js` },
84 { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` },
85 ]),
Matteo Scandolod819c922016-12-02 14:06:14 -080086 new webpack.optimize.OccurrenceOrderPlugin(),
87 new webpack.NoErrorsPlugin(),
88 new HtmlWebpackPlugin({
89 template: conf.path.src('index.html')
Matteo Scandolo042ea632017-03-01 19:02:34 -080090 }),
91 new ExtractTextPlugin('index-[contenthash].css'),
Matteo Scandolod819c922016-12-02 14:06:14 -080092 ],
93 postcss: () => [autoprefixer],
94 debug: true,
95 devtool: 'source-map',
96 output: {
97 path: path.join(process.cwd(), conf.paths.tmp),
Matteo Scandolo042ea632017-03-01 19:02:34 -080098 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'
107 ]
108 },
Matteo Scandolo042ea632017-03-01 19:02:34 -0800109 entry: {
Matteo Scandolo520a8a12017-03-10 17:31:37 -0800110 index: `./${conf.path.src('index')}`,
Matteo Scandolo042ea632017-03-01 19:02:34 -0800111 loader: `./${conf.path.src('/app/style/imports/loader.scss')}`
112 },
Matteo Scandolod819c922016-12-02 14:06:14 -0800113 ts: {
114 configFileName: 'tsconfig.json'
115 },
116 tslint: {
117 configuration: require('../tslint.json')
Matteo Scandolo266907e2016-12-20 13:41:42 -0800118 },
119 stats: {
120 colors: true,
121 modules: true,
122 reasons: true,
123 errorDetails: true
Matteo Scandolod819c922016-12-02 14:06:14 -0800124 }
125};