forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.ts
More file actions
74 lines (69 loc) · 2.64 KB
/
gulpfile.ts
File metadata and controls
74 lines (69 loc) · 2.64 KB
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
import log from 'fancy-log'
import gulp from 'gulp'
import createWebpackCompiler, { Stats } from 'webpack'
import WebpackDevServer, { addDevServerEntrypoints } from 'webpack-dev-server'
import { copyIntegrationAssets, watchIntegrationAssets } from '../browser/gulpfile'
import { graphQLTypes, schema, watchGraphQLTypes, watchSchema } from '../shared/gulpfile'
import webpackConfig from './webpack.config'
const WEBPACK_STATS_OPTIONS: Stats.ToStringOptions & { colors?: boolean } = {
all: false,
timings: true,
errors: true,
warnings: true,
colors: true,
}
const logWebpackStats = (stats: Stats): void => {
log(stats.toString(WEBPACK_STATS_OPTIONS))
}
export async function webpack(): Promise<void> {
const compiler = createWebpackCompiler(webpackConfig)
const stats = await new Promise<Stats>((resolve, reject) => {
compiler.run((err, stats) => (err ? reject(err) : resolve(stats)))
})
logWebpackStats(stats)
if (stats.hasErrors()) {
throw Object.assign(new Error('Failed to compile'), { showStack: false })
}
}
export async function webpackDevServer(): Promise<void> {
const options: WebpackDevServer.Configuration & { liveReload?: boolean } = {
hot: !process.env.NO_HOT,
inline: !process.env.NO_HOT,
allowedHosts: ['.host.docker.internal'],
host: 'localhost',
port: 3080,
publicPath: '/.assets/',
contentBase: './ui/assets',
stats: WEBPACK_STATS_OPTIONS,
noInfo: false,
disableHostCheck: true,
proxy: {
'/': {
target: 'http://localhost:3081',
// Avoid crashing on "read ECONNRESET".
onError: err => console.error(err),
onProxyReqWs: (_proxyReq, _req, socket) =>
socket.on('error', err => console.error('WebSocket proxy error:', err)),
},
},
}
addDevServerEntrypoints(webpackConfig, options)
const server = new WebpackDevServer(createWebpackCompiler(webpackConfig), options)
await new Promise<void>((resolve, reject) => {
server.listen(3080, '0.0.0.0', (err?: Error) => (err ? reject(err) : resolve()))
})
}
/**
* Builds everything.
*/
export const build = gulp.parallel(
gulp.series(gulp.parallel(schema, graphQLTypes), gulp.parallel(webpack, copyIntegrationAssets))
)
/**
* Watches everything and rebuilds on file changes.
*/
export const watch = gulp.series(
// Ensure the typings that TypeScript depends on are build to avoid first-time-run errors
gulp.parallel(schema, graphQLTypes),
gulp.parallel(watchSchema, watchGraphQLTypes, webpackDevServer, watchIntegrationAssets)
)