/
webpack.js
171 lines (146 loc) · 3.23 KB
/
webpack.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
170
// Webpack bundler implementation
'use strict';
//var fs = require('fs'),
// path = require('path'),
// log = require('../../utils/log');
module.exports = function(webpack) {
return function(ss,options){
var bundler = {
define: define,
load: load,
toMinifiedCSS: toMinifiedCSS,
toMinifiedJS: toMinifiedJS,
asset: {
entries: entries,
html: assetHTML,
loader: assetLoader,
systemModule: systemModule,
js: assetJS,
worker: assetWorker,
start: assetStart,
css: assetCSS
}
};
/**
*
* @param client
* @param paths
* @returns {*}
*/
function define(client, paths) {
if (typeof paths.view !== 'string') {
throw new Error('You may only define one HTML view per single-page client. Please pass a filename as a string, not an Array');
}
if (paths.view.indexOf('.') === -1) {
throw new Error('The \'' + paths.view + '\' view must have a valid HTML extension (such as .html or .jade)');
}
bundler.client = client;
// Define new client object
client.paths = ss.bundler.sourcePaths(paths);
return ss.bundler.destsFor(client);
}
function load() {
}
/**
* list of entries for an asset type relative to the client directory
*
* @param assetType
* @returns {*}
*/
function entries(assetType) {
return ss.bundler.entries(bundler.client, assetType);
}
/**
*
* @param path
* @param opts
* @param cb
* @returns {*}
*/
function assetCSS(path, opts, cb) {
return ss.bundler.loadFile(path, 'css', opts, cb);
}
/**
*
* @param path
* @param opts
* @param cb
* @returns {*}
*/
function assetHTML(path, opts, cb) {
return ss.bundler.loadFile(path, 'html', opts, cb);
}
/**
*
* @param cb
*/
function assetLoader() {
return { type: 'loader', names: [], content: ';/* loader */' };
}
/**
*
* @param name
* @param content
* @param options
* @returns {boolean}
*/
function systemModule(name) {
switch(name) {
case "eventemitter2":
case "socketstream":
default:
//if (client.includes.system) {
return ss.bundler.systemModule(name)
//}
}
}
/**
*
* @param path
* @param opts
* @param cb
*/
function assetJS(path, opts, cb) {
webpack({}, function() {
cb('//');
});
}
/**
*
* @param cb
* @returns {*}
*/
function assetStart() {
var output = ss.bundler.startCode(bundler.client);
return output;
}
/**
*
* @param path
* @param opts
* @param cb
*/
function assetWorker(path, opts, cb) {
webpack({}, function() {
cb('//');
});
}
/**
*
* @param files
* @returns {*}
*/
function toMinifiedCSS(files) {
return ss.bundler.minifyCSS(files);
}
/**
*
* @param files
* @returns {string}
*/
function toMinifiedJS() {
return '// minified JS for '+bundler.client.name;
}
return bundler;
};
};