forked from ManageIQ/ui-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
142 lines (137 loc) · 3.7 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"use strict";
const settings = require('./application-settings.js');
const webpack = require('webpack'),
path = require('path'),
NgAnnotatePlugin = require('ng-annotate-webpack-plugin'),
BrowserSyncPlugin = require('browser-sync-webpack-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
spa = require('browser-sync-spa');
module.exports = (env) => {
let production = env && env.NODE_ENV === 'production';
let test = env && env.test;
const appEntry = {
[settings.appName]: [
settings.sassEntryPoint,
settings.tsEntryPoint,
].concat(settings.tsModules),
'demo-app': [
'./demo/index.ts',
'./demo/styles/demo-app.scss',
],
};
const plugins = [
new CopyWebpackPlugin([
{from: __dirname + '/demo/data', to: 'data'},
{from: __dirname + '/demo/assets', to: 'assets'},
]),
new HtmlWebpackPlugin({
title: 'ManageIQ Common Components',
template: 'demo/template-index.ejs', // Load a custom template
inject: 'body',
}),
production ? new webpack.optimize.CommonsChunkPlugin({
name: settings.appName,
filename: settings.javascriptFolder + '/' + settings.appName + settings.isMinified(production),
}) : undefined,
new ExtractTextPlugin(settings.stylesheetPath),
new NgAnnotatePlugin({add: true}),
production ? new webpack.optimize.UglifyJsPlugin({
warnings: false,
minimize: true,
drop_console: true,
}) : undefined,
].filter(p => !!p);
return {
context: __dirname,
entry: appEntry,
output: {
path: settings.outputFolder,
publicPath: '.',
filename: settings.javascriptFolder + "/[name]" + settings.isMinified(production),
},
resolve: {
extensions: ['.ts', '.js'],
},
stats: {
colors: true,
reasons: true,
},
devtool: !production && 'source-map',
module: {
rules: [
{
test: /\.ts?$/,
exclude: /(node_modules|libs)/,
loader: 'tslint-loader',
enforce: 'pre',
options: {emitErrors: true},
},
{
test: /\.ts$/,
exclude: /(node_modules|libs)/,
loader: 'awesome-typescript-loader',
},
{
test: /\.html$/,
exclude: /(node_modules|libs|dist|tsd)/,
loader: 'raw-loader',
},
{
test: /\.scss/,
exclude: /(node_modules|lib)/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader!sass-loader',
}),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader!sass-loader',
}),
},
{
test: /\.(png|jpg|gif|svg|woff|ttf|eot)/,
loader: 'url-loader?limit=20480',
},
{
test: /\.json$/,
loader: 'json-loader',
},
],
},
plugins: [
...plugins,
new BrowserSyncPlugin({
host: 'localhost',
port: 4000,
server: {baseDir: [__dirname + settings.distFolder]},
open: !test,
middleware: [
{
route: "/data",
handle: function (req, res, next) {
req.method = 'GET';
return next();
},
},
],
}, {
use: spa({
selector: '[ng-app]',
}),
}),
],
externals: {
'angular': 'angular',
'lodash': '_',
'__': '__',
},
watchOptions: {
ignored: ['**/.*.sw[po]'],
},
};
};