-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
executable file
·208 lines (183 loc) · 6.07 KB
/
Gulpfile.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const gulp = require('gulp'),
del = require('del'),
runSequence = require('run-sequence'),
Webpack = require('webpack'),
path = require('path'),
Gutil = require('gulp-util'),
systemModulesBuilder = require('./Gulp/systemModulesBuilder'),
buildStage = require('./Gulp/buildStage'),
bundleTemplates = require('gulp-bundle-templates');
const webpackStream = require('webpack-stream');
const named = require('vinyl-named');
const rename = require('gulp-rename');
const filelist = require('gulp-filelist');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
gulp.task('clean', () => {
return del(['dist']);
});
gulp.task('copy:userspace', [], () => {
return gulp.src(['src/userSpace/**'])
.pipe(gulp.dest('dist/userSpace'));
});
gulp.task('copy:styles', [], () => {
return gulp.src('src/core/styles/**')
.pipe(gulp.dest('dist/styles'));
});
gulp.task('copy:fonts', [], () => {
return gulp.src('src/core/fonts/**')
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('copy', ['copy:userspace', 'copy:styles', 'copy:fonts']);
gulp.task('build:html', [], () => {
return gulp.src('src/index.html')
.pipe(bundleTemplates())
.pipe(gulp.dest('dist/'));
});
gulp.task('build:static-volume', ['copy:userspace'], () => {
return gulp.src('dist/userSpace/**')
.pipe(filelist('static-volume.json', { relative: true }))
.pipe(gulp.dest('build/kernel/'));
});
gulp.task('webpack', [buildStage, systemModulesBuilder, 'build:static-volume'], (callback) => {
// run webpack
Webpack({
entry: {
io: path.join(__dirname, 'build', 'io', 'index.js'),
},
context : path.join(__dirname, 'build'),
output : {
pathinfo: true,
path : path.join(__dirname, 'dist'),
filename : '[name].js',
sourceMapFilename: '[file].map',
},
module: {
rules: [{
test: /\.html$/,
use: ['dom-loader', 'html-loader']
}, {
include: path.resolve(__dirname, 'build/threading'),
sideEffects: false
}],
},
externals: ['fs'],
plugins : [
new Webpack.IgnorePlugin(/vertx/),
],
optimization: {
concatenateModules: false,
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
mangle: false,
compress: false,
output: {
beautify: true,
}
}
})
]
},
devtool: 'source-map',
mode: 'production',
}, (err, stats) => {
if(err) throw new Gutil.PluginError('webpack', err);
Gutil.log('[webpack]', stats.toString());
callback();
});
});
gulp.task('build:threads', [buildStage, systemModulesBuilder, 'build:static-volume'], () => {
return gulp.src(['build/kernel/index.js', 'build/process/index.js'])
.pipe(named((file) => {
const packageName = path.parse(file.path).dir.match(/[^/]*$/)[0];
return packageName;
}))
.pipe(webpackStream({
context : path.join(__dirname, 'build'),
output: {
filename: path.join('[name].js'),
sourceMapFilename: '[file].map'
},
module: {
rules: [{
include: path.resolve(__dirname, 'build/threading'),
sideEffects: false
}],
},
optimization: {
concatenateModules: false,
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
output: {
beautify: true,
},
mangle: false,
compress: false,
}
})
]
},
mode: 'production',
target: 'webworker',
devtool: 'source-map',
}, require('webpack'))
.on('error', (error) => {
Gutil.log(error.message);
process.exit(1);
}))
.pipe(gulp.dest('dist/'));
});
const getPackageName = function(file) {
const packageName = path.parse(file.path).dir.match(/[^/]*$/)[0];
return packageName;
};
const transformFileToPackage = function(path) {
path.basename = path.dirname;
path.dirname = '';
return path;
};
gulp.task('build:packages', () => {
return gulp.src('src/packages/*/index.js')
.pipe(named(getPackageName))
.pipe(webpackStream({
output: {
filename: path.join('[name].js'),
libraryTarget: 'umd',
library: '[name]',
},
externals: ['System']
}))
.pipe(gulp.dest('dist/packages/'));
});
gulp.task('build:packages:views', () => {
return gulp.src('src/packages/*/views.js')
.pipe(named(getPackageName))
.pipe(webpackStream({
output: {
filename: path.join('[name].views.js'),
libraryTarget: 'umd',
library: '[name]',
},
module: {
rules: [{
test: /\.html$/,
use: ['text-loader']
}],
},
}))
.pipe(gulp.dest('dist/packages/'));
});
gulp.task('copy:package-manifests', () => {
return gulp.src('src/packages/**/manifest.json')
.pipe(rename(transformFileToPackage))
.pipe(gulp.dest('dist/packages/'));
});
gulp.task('watch', ['default'], () => {
gulp.watch(['src/**/*.*'], ['copyToDist']);
});
gulp.task('default', (cb) => {
runSequence('clean', ['copy', 'build:html', 'build:packages', 'copy:package-manifests', 'build:packages:views', 'build:threads', 'webpack'], cb);
});