-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
109 lines (100 loc) · 2.35 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
var webpack = require('webpack'),
path = require('path'),
yargs = require('yargs');
var glob = require('glob');
var fs = require('fs');
var libraryName = 'iland',
outputFile;
var plugins = [];
if (yargs.argv.p) {
plugins.push(new DtsBundlePlugin());
plugins.push(new webpack.optimize.UglifyJsPlugin({minimize: true}));
outputFile = libraryName + ".min.js";
} else {
outputFile = libraryName + ".js";
}
var filter = function(it) {
return it.indexOf('__mocks__') < 0 && it.indexOf('__tests__') < 0;
};
var tsFiles = glob.sync('./src/sdk/**/*.ts').filter(filter);
var index = '';
for (var i in tsFiles) {
index += 'export * from \'../.' + tsFiles[i] + '\';\n';
}
var buildDir = './build';
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
}
var indexDir = buildDir + '/build';
if (!fs.existsSync(indexDir)) {
fs.mkdirSync(indexDir);
}
var indexFilename = indexDir + '/index.ts';
fs.writeFileSync(indexFilename, index);
var config = {
entry: indexFilename,
output: {
filename: outputFile,
path: path.resolve(__dirname, 'build'),
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: {
"axios": {
commonjs: "axios",
commonjs2: "axios",
amd: "axios",
root: "axios"
},
"keycloak-js": {
commonjs: "keycloak-js",
commonjs2: "keycloak-js",
amd: "keycloak-js",
root: "Keycloak"
},
"rxjs": {
commonjs: "rxjs",
commonjs2: "rxjs",
amd: "rxjs",
root: "rxjs"
},
"qs": {
commonjs: "qs",
commonjs2: "qs",
amd: "qs",
root: "qs"
}
},
resolve: {
// Add '.ts' and '.tsx' as a resolvable extension.
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
{
test: /\.tsx?$/,
exclude: /.*?node_modules/,
loader: "ts-loader" }
]
},
plugins: plugins
};
module.exports = config;
function DtsBundlePlugin() {
}
DtsBundlePlugin.prototype.apply = function(compiler) {
compiler.plugin('done', function() {
var dts = require('dts-bundle');
dts.bundle({
name: libraryName,
main: 'build/build/src/sdk/**/*.d.ts',
exclude: function(it) {
return !filter(it);
},
out: '../../../' + libraryName + '.d.ts',
removeSource: true,
outputAsModuleFolder: true
});
});
};