blob: 7f5197e14eb2cef42ef44f582afe5cf988147965 [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 brand = process.env.BRAND || 'cord';
Matteo Scandolod819c922016-12-02 14:06:14 -080028
29module.exports = {
30 module: {
31 preLoaders: [
32 {
33 test: /\.ts$/,
34 exclude: /node_modules/,
35 loader: 'tslint'
36 }
37 ],
38
39 loaders: [
40 {
41 test: /.json$/,
42 loaders: [
43 'json'
44 ]
45 },
46 {
47 test: /\.(css|scss)$/,
Matteo Scandolo042ea632017-03-01 19:02:34 -080048 loaders: ExtractTextPlugin.extract({
49 fallbackLoader: 'style',
50 loader: [
51 'css',
52 'resolve-url-loader',
53 'sass?sourceMap',
54 'postcss'
55 ]
56 })
Matteo Scandolod819c922016-12-02 14:06:14 -080057 },
58 {
59 test: /\.ts$/,
60 exclude: /node_modules/,
61 loaders: [
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080062 'ng-annotate',
Matteo Scandolod819c922016-12-02 14:06:14 -080063 'ts'
64 ]
65 },
66 {
67 test: /.html$/,
68 loaders: [
Matteo Scandolo99fface2016-12-21 15:37:23 -080069 'html?' + JSON.stringify({
70 attrs: ["img:src", "img:ng-src"]
71 })
Matteo Scandolod819c922016-12-02 14:06:14 -080072 ]
Matteo Scandolo266907e2016-12-20 13:41:42 -080073 },
74 {
75 test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif|jpeg)$/,
76 loader: 'url-loader?limit=100000'
Matteo Scandolod819c922016-12-02 14:06:14 -080077 }
78 ]
79 },
80 plugins: [
Matteo Scandolo828d1e82017-01-17 14:49:38 -080081 new CopyWebpackPlugin([
Matteo Scandolo5fda6a82017-09-08 15:43:45 -070082 { from: `./conf/app/app.config.production.js`, to: `app.config.js` },
Matteo Scandolo828d1e82017-01-17 14:49:38 -080083 { from: `./conf/app/style.config.${brand}.js`, to: `style.config.js` },
84 ]),
Matteo Scandolod819c922016-12-02 14:06:14 -080085 new webpack.optimize.OccurrenceOrderPlugin(),
86 new webpack.NoErrorsPlugin(),
87 new HtmlWebpackPlugin({
88 template: conf.path.src('index.html')
Matteo Scandolo042ea632017-03-01 19:02:34 -080089 }),
90 new ExtractTextPlugin('index-[contenthash].css'),
Matteo Scandolod819c922016-12-02 14:06:14 -080091 ],
92 postcss: () => [autoprefixer],
93 debug: true,
94 devtool: 'source-map',
95 output: {
96 path: path.join(process.cwd(), conf.paths.tmp),
Matteo Scandolo042ea632017-03-01 19:02:34 -080097 filename: '[name].js'
Matteo Scandolod819c922016-12-02 14:06:14 -080098 },
99 resolve: {
100 extensions: [
101 '',
102 '.webpack.js',
103 '.web.js',
104 '.js',
105 '.ts'
106 ]
107 },
Matteo Scandolo042ea632017-03-01 19:02:34 -0800108 entry: {
Matteo Scandolo520a8a12017-03-10 17:31:37 -0800109 index: `./${conf.path.src('index')}`,
Matteo Scandolo042ea632017-03-01 19:02:34 -0800110 loader: `./${conf.path.src('/app/style/imports/loader.scss')}`
111 },
Matteo Scandolod819c922016-12-02 14:06:14 -0800112 ts: {
113 configFileName: 'tsconfig.json'
114 },
115 tslint: {
116 configuration: require('../tslint.json')
Matteo Scandolo266907e2016-12-20 13:41:42 -0800117 },
118 stats: {
119 colors: true,
120 modules: true,
121 reasons: true,
122 errorDetails: true
Matteo Scandolod819c922016-12-02 14:06:14 -0800123 }
124};