This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.make.js
169 lines (152 loc) · 4.05 KB
/
webpack.make.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict';
var webpack = require('webpack');
var yargs = require('yargs').argv;
var path = require('path');
var helpers = require(process.cwd() + '/webpack.helpers.js');
module.exports = function makeWebpackConfig(options) {
/**
* Environment type
* BUILD is for generating minified builds
* TEST is for generating test builds
*/
var BUILD = !!options.BUILD;
var TEST = !!options.TEST;
/**
* Config
* Reference: http://webpack.github.io/docs/configuration.html
* This is the object where all configuration gets set
*/
var config = {};
/**
* Entry
* Reference: http://webpack.github.io/docs/configuration.html#entry
* Should be an empty object if it's generating a test build
* Karma will set this when it's a test build
*/
if (TEST) {
config.entry = {}
} else {
config.entry = {
'pigeon': ['./lib/index.ts'],
'pigeon.min': ['./lib/index.ts']
};
}
/**
* Output
* Reference: http://webpack.github.io/docs/configuration.html#output
* Should be an empty object if it's generating a test build
* Karma will handle setting it up for you when it's a test build
*/
if (TEST) {
config.output = {}
} else {
config.output = {
path: helpers.root('dist'),
filename: '[name].js',
sourceMapFilename: '[name].map',
// export itself to a global var
libraryTarget: "umd"
};
}
/**
* Devtool
* Reference: http://webpack.github.io/docs/configuration.html#devtool
* Type of sourcemap to use per build type
*/
if (TEST) {
config.devtool = 'inline-source-map';
} else if (BUILD) {
config.debug = true;
config.devtool = 'source-map';
} else {
config.debug = true;
config.devtool = 'eval';
}
/**
* Loaders
* Reference: http://webpack.github.io/docs/configuration.html#module-loaders
* List: http://webpack.github.io/docs/list-of-loaders.html
* This handles most of the magic responsible for converting modules
*/
// Initialize module
config.module = {
preLoaders: [
{
test: /\.ts$/,
loader: 'tslint'
}
],
loaders: []
};
// TS-LOADER
if (TEST) {
config.module.loaders.push(
{
test: /\.ts$/,
loader: 'ts-loader'
}
);
} else {
config.module.loaders.push(
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: [/\.(spec|e2e|async)\.ts$/]
}
);
}
/**
* TSLINT
*/
// Other module loader config
config.tslint = {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
};
/**
* Sinon
* This two config items are needed to be able to use sinon in your tests
*/
config.module.noParse = [
/\/sinon.js/
];
config.resolve = {
alias: {
'sinon': 'sinon/pkg/sinon'
}
};
/**
* Plugins
* Reference: http://webpack.github.io/docs/configuration.html#plugins
* List: http://webpack.github.io/docs/list-of-plugins.html
*/
config.plugins = [];
if (BUILD) {
config.plugins.push(new webpack.BannerPlugin(helpers.getBanner()));
}
// Add build specific plugins
if (BUILD) {
config.plugins.push(
// Reference: http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin
// Only emit files when there are no errors
new webpack.NoErrorsPlugin(),
// Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
// Dedupe modules in the output
new webpack.optimize.DedupePlugin(),
// Reference: http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
// Minify all javascript, switch loaders to minimizing mode
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
mangle: {
// You can specify all variables that should not be mangled.
// For example if your vendor dependency doesn't use modules
// and relies on global variables. Most of angular modules relies on
// angular global variable, so we should keep it unchanged
except: ['exports', 'require']
}
})
)
}
return config;
};