Skip to content

Commit 7e872aa

Browse files
committed
Add webpack watch gulp task
Now, when running `npm run watch`, both the regular tsc command and the webpack command will be run in watch mode. The raw gulp tasks are now: - `gulp watchView` to watch webpack compilation. - `gulp watchCss` to watch for css changes. - `gulp compileView` to compile the webpack once and exit. However, stats are no longer being printed out. Not sure why.
1 parent ef127c2 commit 7e872aa

4 files changed

Lines changed: 47 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: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,24 @@ 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+
...
11+
config,
12+
watch: true,
13+
watchOptions: {
14+
aggregateTimeout: 200,
15+
poll: 1000,
16+
}
17+
};
18+
doWebpack(watchConfig, false, cb);
19+
}
20+
21+
function doWebpack(internalConfig: webpack.Configuration, failOnError: boolean, cb: (err?: Error) => void) {
22+
const resultCb = (error: Error | undefined, stats?: webpack.Stats) => {
623
if (error) {
724
cb(error);
825
}
@@ -20,11 +37,16 @@ export function compileView(cb: (err?: Error) => void) {
2037
errors: true
2138
}));
2239
if (stats.hasErrors()) {
23-
cb(new Error('Compilation errors detected.'));
24-
return;
40+
if (failOnError) {
41+
cb(new Error('Compilation errors detected.'));
42+
return;
43+
} else {
44+
console.error('Compilation errors detected.');
45+
}
2546
}
47+
cb();
2648
}
49+
};
2750

28-
cb();
29-
});
51+
webpack(internalConfig, resultCb);
3052
}

extensions/ql-vscode/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,8 @@
10721072
"build": "gulp",
10731073
"watch": "npm-run-all -p watch:*",
10741074
"watch:extension": "tsc --watch",
1075+
"watch:webpack": "gulp watchView",
1076+
"watch:css": "gulp watchCss",
10751077
"test": "mocha --exit -r ts-node/register test/pure-tests/**/*.ts",
10761078
"preintegration": "rm -rf ./out/vscode-tests && gulp",
10771079
"integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace",
@@ -1119,9 +1121,9 @@
11191121
"@types/chai-as-promised": "~7.1.2",
11201122
"@types/child-process-promise": "^2.2.1",
11211123
"@types/classnames": "~2.2.9",
1122-
"@types/del": "^4.0.0",
11231124
"@types/d3": "^6.2.0",
11241125
"@types/d3-graphviz": "^2.6.6",
1126+
"@types/del": "^4.0.0",
11251127
"@types/fs-extra": "^9.0.6",
11261128
"@types/glob": "^7.1.1",
11271129
"@types/google-protobuf": "^3.2.7",

0 commit comments

Comments
 (0)