@@ -20,59 +20,32 @@ import gulpAngularTemplatecache from 'gulp-angular-templatecache';
20
20
import gulpClosureCompiler from 'gulp-closure-compiler' ;
21
21
import gulpEslint from 'gulp-eslint' ;
22
22
import gulpMinifyHtml from 'gulp-minify-html' ;
23
- import lodash from 'lodash' ;
24
23
import path from 'path' ;
24
+ import webpackStream from 'webpack-stream' ;
25
25
26
26
import conf from './conf' ;
27
27
28
28
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
-
50
29
/**
51
30
* Compiles frontend JavaScript files into development bundle located in {conf.paths.serve}
52
31
* directory. This has to be done because currently browsers do not handle ES6 syntax and
53
32
* modules correctly.
54
33
*
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.
57
35
*/
58
36
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 : / \. j s $ / , exclude : / n o d e _ m o d u l e s / , 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 ) )
76
49
. pipe ( gulp . dest ( conf . paths . serve ) )
77
50
} ) ;
78
51
@@ -82,35 +55,47 @@ gulp.task('scripts', ['create-serve-folders'], function() {
82
55
* directory.
83
56
*/
84
57
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
+ } ;
114
99
115
100
return gulp . src ( [
116
101
// Application source files.
0 commit comments