forked from skatejs/skatejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-blocks.js
89 lines (79 loc) · 1.64 KB
/
webpack-blocks.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
const { entryPoint, group, setOutput, sourceMaps } = require('@webpack-blocks/webpack2');
const babel = require('@webpack-blocks/babel6');
const path = require('path');
function min () {
return prod() ? '.min' : '';
}
function pack () {
return require(path.join(process.cwd(), 'package.json'));
}
function prod () {
return process.argv.indexOf('-p') > -1;
}
function entries () {
return entryPoint({
[`dist/index${min()}.js`]: './src/index.js'
});
}
function entriesWithDeps () {
return entryPoint({
[`dist/index-with-deps${min()}.js`]: './src/index.js'
});
}
function externals () {
const {
dependencies,
devDependencies,
externals,
optionalDependencies,
peerDependencies
} = pack();
return () => ({
externals: externals || Object.keys(
Object.assign(
{},
dependencies,
devDependencies,
optionalDependencies,
peerDependencies
)
)
});
}
function output (userDefinedOutput) {
const { global, name } = pack();
const temp = Object.assign({}, {
filename: '[name]',
library: global || name,
libraryTarget: 'umd',
path: './',
sourceMapFilename: '[file].map'
}, userDefinedOutput);
return setOutput(temp);
}
// Preset for generating a bundle with only the src files.
function main () {
return group([
babel(),
entries(),
externals(),
output(),
sourceMaps()
]);
}
// Preset for generating a bundle including the dependencies.
function bundle () {
return group([
babel(),
entriesWithDeps(),
output(),
sourceMaps()
]);
}
module.exports = {
bundle,
entries,
externals,
main,
output
};