Initialize the UI code
[holmes/rule-management.git] / rulemgt / src / main / frontend / src / config / webpack.common.js
1 /* Copyright 2017 ZTE Corporation.
2  *
3  *Licensed under the Apache License, Version 2.0 (the "License");
4  *you may not use this file except in compliance with the License.
5  *You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
16 const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
17 const CopyWebpackPlugin = require('copy-webpack-plugin');
18 const HtmlWebpackPlugin = require('html-webpack-plugin');
19 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
20
21 const webpack = require('webpack');
22 const helpers = require('./helpers');
23 const path = require('path');
24
25
26
27
28
29 module.exports = {
30     entry: {
31         'main': './alarm/main.browser.ts',
32         'vendor': './alarm/vendor.ts',
33         'polyfills': './alarm/polyfills.browser.ts'
34     },
35     resolve: {
36
37         extensions: ['.js', '.ts', '.json'],
38     },
39     module: {
40
41         rules: [
42             {
43                 test: /\.ts$/,
44                 use: [
45
46                     {
47                         loader: 'awesome-typescript-loader',
48                         options: {
49                         }
50                     },
51                     {
52                         loader: 'angular2-template-loader'
53                     }
54                 ],
55                 exclude: [/\.(spec|e2e)\.ts$/]
56             },
57
58             {
59                 test: /\.json$/,
60                 use: 'json-loader'
61             },
62             {
63                 test: /\.css$/,
64                 use: ['to-string-loader', 'css-loader?sourceMap'],
65                 include: helpers.root('alarm', 'app'),
66                 exclude: [helpers.root('alarm/assets'), helpers.root('public')]
67             },
68             {
69                 test: /\.html$/,
70                 use: 'raw-loader',
71                 include: [helpers.root('alarm/app')],
72                 exclude: [helpers.root('alarm/index.html')]
73             },
74
75
76             {
77                 test: /\.(png|jpe?g|gif|ico|svg)$/,
78                 include: [helpers.root('public')
79                 ],
80                 use: 'file-loader?name=assets/images/[name].[hash].[ext]'
81             },
82
83
84             {
85                 test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
86                 include: [helpers.root('public', 'thirdparty')
87                 ],
88                 use: 'file-loader?name=assets/fonts/[name].[hash].[ext]'
89             }
90
91         ],
92
93     },
94
95     plugins: [
96
97         new CheckerPlugin(),
98
99         new ContextReplacementPlugin(
100             /angular(\\|\/)core(\\|\/)alarm(\\|\/)linker/,
101             helpers.root('alarm'),
102             {
103             }
104         ),
105
106         new HtmlWebpackPlugin({
107             template: 'alarm/index.html',
108         }),
109
110         new webpack.optimize.CommonsChunkPlugin({
111             name: ['main', 'vendor', 'polyfills']
112         }),
113
114     ]
115 };