-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.lib.js
150 lines (145 loc) · 3.66 KB
/
webpack.lib.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
let glob = require('glob');
let _ = require('lodash');
let webpack = require('webpack');
let UglifyJsPlugin = require('uglifyjs-webpack-plugin');
let path = require('path');
let pkg = require('./package.json');
let now = new Date();
let year = now.getFullYear();
let banner = `${pkg.name} v${pkg.version} (${pkg.homepage})
${pkg.description}
Copyright 2013-${year} ${pkg.author}`;
let SRC = './src/lib/';
let SUFFIX = '/index.ts';
let moduleFiles = glob.sync('./src/lib/**/index.ts');
let entryFiles = _.reduce(
moduleFiles,
function(obj, file) {
let key = file.substring(file.indexOf(SRC) + SRC.length, file.indexOf(SUFFIX));
_.set(obj, key, [file]); // set as array to workaround webpack entry path limitation
return obj;
},
{
'momentum-ui-angularjs.umd': './src/lib/momentum-ui-angularjs.ts',
'momentum-ui-angularjs.umd.min': './src/lib/momentum-ui-angularjs.ts',
},
);
let config = {
mode: 'production',
entry: entryFiles,
devtool: 'source-map',
output: {
path: __dirname + '/bundles',
filename: '[name].js',
libraryTarget: 'umd',
umdNamedDefine: true,
},
externals: {
'angular': {
amd: 'angular',
commonjs: 'angular',
commonjs2: 'angular',
root: "angular",
},
'angular-animate': {
amd: 'angular-animate',
commonjs: 'angular-animate',
commonjs2: 'angular-animate',
root: 'ngAnimate',
},
'google-libphonenumber/dist/libphonenumber': {
amd: 'google-libphonenumber/dist/libphonenumber',
commonjs: 'google-libphonenumber/dist/libphonenumber',
commonjs2: 'google-libphonenumber/dist/libphonenumber',
root: 'libphonenumber',
},
'angular-messages': {
amd: 'angular-messages',
commonjs: 'angular-messages',
commonjs2: 'angular-messages',
root: 'ngMessages',
},
'angular-ui-grid': {
amd: 'angular-ui-grid',
commonjs: 'angular-ui-grid',
commonjs2: 'angular-ui-grid',
root: 'uiGrid',
},
'angular-ui-router': {
amd: 'angular-ui-router',
commonjs: 'angular-ui-router',
commonjs2: 'angular-ui-router',
root: 'uiRouter',
},
'imagesloaded': {
amd: 'imagesloaded',
commonjs: 'imagesloaded',
commonjs2: 'imagesloaded',
root: 'imagesloaded',
},
'masonry-layout': {
amd: 'masonry-layout',
commonjs: 'masonry-layout',
commonjs2: 'masonry-layout',
root: 'masonry-layout',
},
'moment': {
amd: 'moment',
commonjs: 'moment',
commonjs2: 'moment',
root: 'moment',
}
},
module: {
rules: [
{
test: /\.ts$/,
use: ['ng-annotate-loader', 'awesome-typescript-loader'],
exclude: [/node_modules/],
},
{
test: /\.html$/,
exclude: [/\/app\/index.html$/, /node_modules/, /\/src\/docs/],
use: [
{ loader: 'html-loader' },
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
imagesloaded: 'imagesloaded/imagesloaded.pkgd.js',
'masonry-layout': 'masonry-layout/dist/masonry.pkgd.js'
},
},
resolveLoader: {
modules: [path.join(__dirname, 'node_modules')],
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
mangle: true,
compress: true,
},
include: /\.min\.js$/,
}),
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
mangle: false,
compress: false,
},
exclude: /\.min\.js$/,
})
]
},
plugins: [
new webpack.BannerPlugin(banner),
],
};
module.exports = config;