-
Notifications
You must be signed in to change notification settings - Fork 632
/
bundle.js
executable file
·89 lines (81 loc) · 1.77 KB
/
bundle.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
#!/usr/bin/env node
'use strict';
var path = require('path');
var webpack = require('webpack');
var fs = require('fs');
var VERSION = JSON.parse(fs.readFileSync('./package.json')).version;
var TYPE = '';
var SLIM = false;
var MINIFIED = false;
var TARGET = '';
var args = process.argv.slice(2);
while (args.length > 0) {
if (args.length === 1) {
TARGET = args[0];
} else {
switch (args[0]) {
case '-s':
SLIM = true;
TYPE = '(slim, only works with precompiled templates)';
break;
case '-m':
MINIFIED = true;
break;
}
}
args.shift();
}
var config = {
entry: './index.js',
output: {
path: path.join(__dirname, '../browser'),
filename: TARGET,
library: 'nunjucks',
libraryTarget: 'umd'
},
node: {
process: 'empty'
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/(path|precompile)$/,
'node-libs-browser/mock/empty'),
new webpack.BannerPlugin(
'Browser bundle of nunjucks ' + VERSION + ' ' + TYPE
),
new webpack.DefinePlugin({
'process.env': {
IS_BROWSER: true
}
})
]
};
if (SLIM) {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(
/(nodes|lexer|parser|transformer|compiler|loaders)$/,
'node-libs-browser/mock/empty'
)
);
} else {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(/loaders\.js$/,
'./web-loaders.js')
);
}
if (MINIFIED) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
})
);
}
var outputOptions = {
cached: false,
cachedAssets: false
};
webpack(config).run(function(err, stats) {
if (err) {
throw new Error(err);
}
console.log(stats.toString(outputOptions)); // eslint-disable-line no-console
});