Skip to content

Commit 2ecfbfb

Browse files
authored
Merge pull request #1244 from github/aeisenberg/webpack-watch
Add webpack watch gulp task
2 parents 9508dff + ef28c95 commit 2ecfbfb

4 files changed

Lines changed: 46 additions & 9 deletions

File tree

extensions/ql-vscode/gulpfile.ts/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as gulp from 'gulp';
2-
import { compileTypeScript, watchTypeScript, copyViewCss, cleanOutput } from './typescript';
2+
import { compileTypeScript, watchTypeScript, copyViewCss, cleanOutput, watchCss } from './typescript';
33
import { compileTextMateGrammar } from './textmate';
44
import { copyTestData } from './tests';
5-
import { compileView } from './webpack';
5+
import { compileView, watchView } from './webpack';
66
import { packageExtension } from './package';
77
import { injectAppInsightsKey } from './appInsights';
88

@@ -14,5 +14,15 @@ export const buildWithoutPackage =
1414
)
1515
);
1616

17-
export { cleanOutput, compileTextMateGrammar, watchTypeScript, compileTypeScript, copyTestData, injectAppInsightsKey };
17+
export {
18+
cleanOutput,
19+
compileTextMateGrammar,
20+
watchTypeScript,
21+
watchView,
22+
compileTypeScript,
23+
copyTestData,
24+
injectAppInsightsKey,
25+
compileView,
26+
watchCss
27+
};
1828
export default gulp.series(buildWithoutPackage, injectAppInsightsKey, packageExtension);

extensions/ql-vscode/gulpfile.ts/typescript.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export function watchTypeScript() {
4040
gulp.watch('src/**/*.ts', compileTypeScript);
4141
}
4242

43+
export function watchCss() {
44+
gulp.watch('src/**/*.css', copyViewCss);
45+
}
46+
4347
/** Copy CSS files for the results view into the output directory. */
4448
export function copyViewCss() {
4549
return gulp.src('src/**/view/*.css')

extensions/ql-vscode/gulpfile.ts/webpack.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ import * as webpack from 'webpack';
22
import { config } from './webpack.config';
33

44
export function compileView(cb: (err?: Error) => void) {
5-
webpack(config).run((error, stats) => {
5+
doWebpack(config, true, cb);
6+
}
7+
8+
export function watchView(cb: (err?: Error) => void) {
9+
const watchConfig = {
10+
...config,
11+
watch: true,
12+
watchOptions: {
13+
aggregateTimeout: 200,
14+
poll: 1000,
15+
}
16+
};
17+
doWebpack(watchConfig, false, cb);
18+
}
19+
20+
function doWebpack(internalConfig: webpack.Configuration, failOnError: boolean, cb: (err?: Error) => void) {
21+
const resultCb = (error: Error | undefined, stats?: webpack.Stats) => {
622
if (error) {
723
cb(error);
824
}
@@ -20,11 +36,16 @@ export function compileView(cb: (err?: Error) => void) {
2036
errors: true
2137
}));
2238
if (stats.hasErrors()) {
23-
cb(new Error('Compilation errors detected.'));
24-
return;
39+
if (failOnError) {
40+
cb(new Error('Compilation errors detected.'));
41+
return;
42+
} else {
43+
console.error('Compilation errors detected.');
44+
}
2545
}
46+
cb();
2647
}
48+
};
2749

28-
cb();
29-
});
50+
webpack(internalConfig, resultCb);
3051
}

extensions/ql-vscode/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@
10981098
"build": "gulp",
10991099
"watch": "npm-run-all -p watch:*",
11001100
"watch:extension": "tsc --watch",
1101+
"watch:webpack": "gulp watchView",
1102+
"watch:css": "gulp watchCss",
11011103
"test": "mocha --exit -r ts-node/register test/pure-tests/**/*.ts",
11021104
"preintegration": "rm -rf ./out/vscode-tests && gulp",
11031105
"integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace",
@@ -1145,9 +1147,9 @@
11451147
"@types/chai-as-promised": "~7.1.2",
11461148
"@types/child-process-promise": "^2.2.1",
11471149
"@types/classnames": "~2.2.9",
1148-
"@types/del": "^4.0.0",
11491150
"@types/d3": "^6.2.0",
11501151
"@types/d3-graphviz": "^2.6.6",
1152+
"@types/del": "^4.0.0",
11511153
"@types/fs-extra": "^9.0.6",
11521154
"@types/glob": "^7.1.1",
11531155
"@types/google-protobuf": "^3.2.7",

0 commit comments

Comments
 (0)