Skip to content

Commit c8ac166

Browse files
committed
Merge pull request #38 from kubernetes/use-webpack-in-dev-build
Use webpack instead of jscompiler in dev builds
2 parents 9dcdfc3 + 11065dc commit c8ac166

File tree

3 files changed

+59
-72
lines changed

3 files changed

+59
-72
lines changed

build/script.js

Lines changed: 55 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,32 @@ import gulpAngularTemplatecache from 'gulp-angular-templatecache';
2020
import gulpClosureCompiler from 'gulp-closure-compiler';
2121
import gulpEslint from 'gulp-eslint';
2222
import gulpMinifyHtml from 'gulp-minify-html';
23-
import lodash from 'lodash';
2423
import path from 'path';
24+
import webpackStream from 'webpack-stream';
2525

2626
import conf from './conf';
2727

2828

29-
/**
30-
* Base Closure Compiler config to be extended in, e.g., prod or dev config.
31-
*/
32-
const closureCompilerBaseConfig = {
33-
// "foo_flag: null" means that a flag is enabled.
34-
compilerFlags: {
35-
angular_pass: null,
36-
closure_entry_point: 'module$src$app$frontend$index_module',
37-
export_local_property_definitions: null,
38-
generate_exports: null,
39-
js_module_root: conf.paths.frontendSrc,
40-
language_in: 'ECMASCRIPT6_STRICT',
41-
language_out: 'ECMASCRIPT3',
42-
manage_closure_dependencies: true,
43-
},
44-
compilerPath: path.join(conf.paths.nodeModules, 'google-closure-compiler/compiler.jar'),
45-
// This makes the compiler faster. Requires Java 7+.
46-
tieredCompilation: true,
47-
};
48-
49-
5029
/**
5130
* Compiles frontend JavaScript files into development bundle located in {conf.paths.serve}
5231
* directory. This has to be done because currently browsers do not handle ES6 syntax and
5332
* modules correctly.
5433
*
55-
* Note that 'create-serve-folders' task is required because closure compiler source maps function
56-
* requires the folders to exist upfront.
34+
* Only dependencies of root application module are included in the bundle.
5735
*/
5836
gulp.task('scripts', ['create-serve-folders'], function() {
59-
let bundleBaseName = 'app-dev';
60-
let closureCompilerConfig = lodash.merge({
61-
fileName: `${bundleBaseName}.js`,
62-
compilerFlags: {
63-
// WHITESPACE_ONLY is not an option because it leaves ES6 modules unmodified. ES6 modules
64-
// arent handled by browsers correctly (yet).
65-
compilation_level: 'SIMPLE_OPTIMIZATIONS',
66-
create_source_map: path.join(conf.paths.serve, `${bundleBaseName}.js.map`),
67-
// Make source map URLs relative to frontend source directory.
68-
source_map_location_mapping: path.relative(conf.paths.base, conf.paths.frontendSrc) + '|',
69-
// Include source map in the output bundle.
70-
output_wrapper: '%output%\n//# sourceMappingURL=' + `${bundleBaseName}.js.map`,
71-
},
72-
}, closureCompilerBaseConfig);
73-
74-
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.js'))
75-
.pipe(gulpClosureCompiler(closureCompilerConfig))
37+
let webpackOptions = {
38+
devtool: 'inline-source-map',
39+
module: {
40+
// ES6 modules have to be preprocessed with Babel loader to work in browsers.
41+
loaders: [{test: /\.js$/, exclude: /node_modules/, loaders: ['babel-loader']}],
42+
},
43+
output: {filename: 'app-dev.js'},
44+
quiet: true,
45+
};
46+
47+
return gulp.src(path.join(conf.paths.frontendSrc, 'index.module.js'))
48+
.pipe(webpackStream(webpackOptions))
7649
.pipe(gulp.dest(conf.paths.serve))
7750
});
7851

@@ -82,35 +55,47 @@ gulp.task('scripts', ['create-serve-folders'], function() {
8255
* directory.
8356
*/
8457
gulp.task('scripts:prod', ['angular-templates'], function() {
85-
let closureCompilerConfig = lodash.merge({
86-
fileName: 'app.js',
87-
compilerFlags: {
88-
compilation_level: 'ADVANCED_OPTIMIZATIONS',
89-
externs: [
90-
path.join(conf.paths.nodeModules,
91-
'google-closure-compiler/contrib/externs/angular-1.4.js'),
92-
path.join(conf.paths.nodeModules,
93-
'google-closure-compiler/contrib/externs/angular-1.4-http-promise_templated.js'),
94-
path.join(conf.paths.nodeModules,
95-
'google-closure-compiler/contrib/externs/angular-1.4-q_templated.js'),
96-
path.join(conf.paths.nodeModules,
97-
'google-closure-compiler/contrib/externs/angular-material.js'),
98-
path.join(conf.paths.nodeModules,
99-
'google-closure-compiler/contrib/externs/angular_ui_router.js'),
100-
path.join(conf.paths.externs, '**/*.js'),
101-
],
102-
// Enable all compiler checks by default and make them errors.
103-
jscomp_error: '*',
104-
// Disable checks that are not applicable to the project.
105-
jscomp_off: [
106-
// This check does not work correctly with ES6.
107-
'inferredConstCheck',
108-
// Let ESLint handle all lint checks.
109-
'lintChecks',
110-
],
111-
use_types_for_optimization: null,
112-
},
113-
}, closureCompilerBaseConfig);
58+
let closureCompilerConfig = {
59+
fileName: 'app.js',
60+
// "foo_flag: null" means that a flag is enabled.
61+
compilerFlags: {
62+
angular_pass: null,
63+
closure_entry_point: 'module$src$app$frontend$index_module',
64+
compilation_level: 'ADVANCED_OPTIMIZATIONS',
65+
export_local_property_definitions: null,
66+
externs: [
67+
path.join(conf.paths.nodeModules,
68+
'google-closure-compiler/contrib/externs/angular-1.4.js'),
69+
path.join(conf.paths.nodeModules,
70+
'google-closure-compiler/contrib/externs/angular-1.4-http-promise_templated.js'),
71+
path.join(conf.paths.nodeModules,
72+
'google-closure-compiler/contrib/externs/angular-1.4-q_templated.js'),
73+
path.join(conf.paths.nodeModules,
74+
'google-closure-compiler/contrib/externs/angular-material.js'),
75+
path.join(conf.paths.nodeModules,
76+
'google-closure-compiler/contrib/externs/angular_ui_router.js'),
77+
path.join(conf.paths.externs, '**/*.js'),
78+
],
79+
generate_exports: null,
80+
js_module_root: conf.paths.frontendSrc,
81+
// Enable all compiler checks by default and make them errors.
82+
jscomp_error: '*',
83+
// Disable checks that are not applicable to the project.
84+
jscomp_off: [
85+
// This check does not work correctly with ES6.
86+
'inferredConstCheck',
87+
// Let ESLint handle all lint checks.
88+
'lintChecks',
89+
],
90+
language_in: 'ECMASCRIPT6_STRICT',
91+
language_out: 'ECMASCRIPT3',
92+
manage_closure_dependencies: true,
93+
use_types_for_optimization: null,
94+
},
95+
compilerPath: path.join(conf.paths.nodeModules, 'google-closure-compiler/compiler.jar'),
96+
// This makes the compiler faster. Requires Java 7+.
97+
tieredCompilation: true,
98+
};
11499

115100
return gulp.src([
116101
// Application source files.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"//": "Specification of this file can be found at: https://docs.npmjs.com/files/package.json",
33
"//": "When a dependency is not needed it should be removed from the list.",
4-
54
"name": "kubernetes-dashboard",
65
"version": "0.0.1",
76
"devDependencies": {
87
"babel": "~5.8.23",
98
"babel-core": "~5.8.25",
9+
"babel-loader": "~5.3.2",
1010
"babelify": "~6.3.0",
1111
"browserify": "~11.2.0",
1212
"browser-sync": "~2.9.2",
@@ -49,6 +49,7 @@
4949
"karma-sourcemap-loader": "~0.3.6",
5050
"lodash": "~3.10.1",
5151
"uglify-save-license": "~0.4.1",
52+
"webpack-stream": "~2.1.1",
5253
"wiredep": "~2.2.2",
5354
"wrench": "~1.5.8"
5455
},

src/app/frontend/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!doctype html>
2-
<html ng-app="kubernetesDashboard" ng-strict-di>
2+
<html ng-app="kubernetesDashboard">
3+
<!-- TODO(bryk): Add ng-strict-di setting for production builds. -->
34
<head>
45
<meta charset="utf-8">
56
<title>Kubernetes Dashboard</title>

0 commit comments

Comments
 (0)