@@ -83,19 +83,6 @@ function minifyTemplate(file) {
83
83
}
84
84
}
85
85
86
- // Build LESS
87
- function transpileLESS ( src ) {
88
- return gulp . src ( src )
89
- . pipe ( sourcemaps . init ( ) )
90
- . pipe ( lessCompiler ( {
91
- paths : [ path . join ( __dirname , 'less' , 'includes' ) ]
92
- } ) )
93
- . pipe ( sourcemaps . write ( ) )
94
- . pipe ( gulp . dest ( function ( file ) {
95
- return __dirname + file . base . slice ( __dirname . length ) ;
96
- } ) ) ;
97
- }
98
-
99
86
// Build and minify LESS separately
100
87
function transpileMinifyLESS ( src ) {
101
88
return gulp . src ( src )
@@ -104,55 +91,22 @@ function transpileMinifyLESS(src) {
104
91
paths : [ path . join ( __dirname , 'less' , 'includes' ) ]
105
92
} ) )
106
93
. pipe ( cssmin ( ) . on ( 'error' , function ( err ) {
107
- console . log ( err ) ;
94
+ console . error ( err ) ;
108
95
} ) )
109
- . pipe ( rename ( { suffix : '.min' } ) )
110
96
. pipe ( sourcemaps . write ( ) )
111
97
. pipe ( gulp . dest ( function ( file ) {
112
- return __dirname + file . base . slice ( __dirname . length ) ;
98
+ return libraryDist + file . base . slice ( __dirname . length ) ;
113
99
} ) ) ;
114
100
}
115
101
116
102
/**
117
103
* LESS
118
104
*/
119
105
120
- // Copy asset LESS to dist/less and replace relative paths for flattened directory
121
- function copyAssetsLess ( ) {
122
- return gulp . src ( [ './src/assets/stylesheets/*.less' ] )
123
- . pipe ( replace ( / \. \. \/ .\. \/ .\. \/ / g, function ( ) {
124
- return '../../../../' ;
125
- } ) )
126
- . pipe ( replace ( / @ i m p o r t ' \. \. \/ \. \. \/ .* \/ / g, function ( ) {
127
- return '@import \'' ;
128
- } ) )
129
- . pipe ( rename ( { dirname : '' } ) )
130
- . pipe ( gulp . dest ( libraryDist + '/dist/less' ) ) ;
131
- }
132
-
133
- // Copy component LESS to dist/less in a flattened directory
134
- function copyLess ( ) {
135
- return gulp . src ( [ './src/app/**/*.less' ] . concat ( globalExcludes ) )
136
- . pipe ( rename ( { dirname : '' } ) )
137
- . pipe ( gulp . dest ( libraryDist + '/dist/less' ) ) ;
138
- }
139
-
140
- /**
141
- * CSS
142
- */
143
-
144
- // Copy CSS to dist/css
145
- function copyCss ( ) {
146
- return gulp . src ( [ './src/assets/stylesheets/*.css' ] , { base : './src/assets/stylesheets' } )
147
- . pipe ( gulp . dest ( function ( file ) {
148
- return libraryDist + '/dist/css' + file . base . slice ( __dirname . length ) ; // save directly to dist
149
- } ) ) ;
150
- }
151
-
152
106
// Stylelint
153
107
function lintCss ( ) {
154
108
return gulp
155
- . src ( [ './src/assets/stylesheets/*.less' , './src/app /**/*.less'] )
109
+ . src ( [ appSrc + ' /**/*.less'] )
156
110
. pipe ( stylelint ( {
157
111
failAfterError : true ,
158
112
reporters : [
@@ -162,13 +116,21 @@ function lintCss() {
162
116
}
163
117
164
118
// Less compilation and minifiction
165
- function minCss ( ) {
166
- return transpileMinifyLESS ( appSrc + '/assets/stylesheets /*.less' ) ;
119
+ function transpileLess ( ) {
120
+ return transpileMinifyLESS ( appSrc + '/** /*.less' ) ;
167
121
}
168
122
169
- // Less compilation
170
- function transpileLess ( ) {
171
- return transpileLESS ( appSrc + '/assets/stylesheets/*.less' ) ;
123
+ // update templates styleUrls
124
+ function postTranspile ( ) {
125
+ return gulp . src ( [ 'dist/**/*.js' ] )
126
+ . pipe ( replace ( / t e m p l a t e U r l : \s / g, "template: require(" ) )
127
+ . pipe ( replace ( / \. h t m l ' , / g, ".html')," ) )
128
+ . pipe ( replace ( / \. h t m l ' / g, ".html')" ) )
129
+ . pipe ( replace ( / s t y l e U r l s : \[ / g, "styles: [require(" ) )
130
+ . pipe ( replace ( / \. l e s s ' ] / g, ".css').toString()]" ) )
131
+ . pipe ( gulp . dest ( function ( file ) {
132
+ return file . base ; // because of Angular's encapsulation, it's natural to save the css where the less-file was
133
+ } ) ) ;
172
134
}
173
135
174
136
/**
@@ -177,7 +139,7 @@ function transpileLess() {
177
139
178
140
// Inline HTML templates in component classes
179
141
function inlineTemplate ( ) {
180
- return gulp . src ( [ './src /app/**/*.ts'] . concat ( globalExcludes ) , { base : './' } )
142
+ return gulp . src ( [ appSrc + ' /app/**/*.ts'] . concat ( globalExcludes ) , { base : './' } )
181
143
. pipe ( replace ( / t e m p l a t e U r l .* \' / g, function ( matched ) {
182
144
let fileName = matched . match ( / \/ .* h t m l / g) . toString ( ) ;
183
145
let dirName = this . file . relative . substring ( 0 , this . file . relative . lastIndexOf ( '/' ) ) ;
@@ -223,18 +185,17 @@ function transpileAot() {
223
185
224
186
// Watch source
225
187
function watch ( ) {
226
- gulp . watch ( [ appSrc + '/app/**/*.ts' , '!' + appSrc + '/app/**/*.spec.ts' ] ) . on ( 'change' , function ( e ) {
227
- console . log ( 'TypeScript file ' + e . path + ' has been changed. Compiling.' ) ;
188
+ gulp . watch ( [ appSrc + '/app/**/*.ts' , '!' + appSrc + '/app/**/*.spec.ts' ] ) . on ( 'change' , function ( path ) {
189
+ console . log ( 'TypeScript file ' + path + ' has been changed. Compiling.' ) ;
190
+ gulp . series ( inlineTemplate , transpile , updateWatchDist ) ( ) ;
228
191
} ) ;
229
- gulp . watch ( [ appSrc + '/app/**/*.less' ] ) . on ( 'change' , function ( e ) {
230
- console . log ( e . path + ' has been changed. Updating.' ) ;
231
- transpileLESS ( e . path ) ;
232
- updateWatchDist ( ) ;
192
+ gulp . watch ( [ appSrc + '/app/**/*.less' , appSrc + '/assets/**/*.less' ] ) . on ( 'change' , function ( path ) {
193
+ console . log ( path + ' has been changed. Updating.' ) ;
194
+ gulp . series ( ( ) => transpileMinifyLESS ( path ) , updateWatchDist ) ( ) ;
233
195
} ) ;
234
- gulp . watch ( [ appSrc + '/app/**/*.html' ] ) . on ( 'change' , function ( e ) {
235
- console . log ( e . path + ' has been changed. Updating.' ) ;
236
- copyToDist ( e . path ) ;
237
- updateWatchDist ( ) ;
196
+ gulp . watch ( [ appSrc + '/app/**/*.html' ] ) . on ( 'change' , function ( path ) {
197
+ console . log ( path + ' has been changed. Updating.' ) ;
198
+ gulp . series ( inlineTemplate , transpile , updateWatchDist ) ( ) ;
238
199
} ) ;
239
200
}
240
201
@@ -249,21 +210,19 @@ function updateWatchDist() {
249
210
/**
250
211
* Tasks
251
212
*/
252
-
253
- const buildLessSeries = gulp . series ( copyAssetsLess , copyLess ) ;
254
- const buildCssSeries = gulp . series ( lintCss , transpileLess , minCss , copyCss ) ;
255
- const buildAotSeries = gulp . series ( inlineTemplate , transpileAot ) ;
213
+ const buildCssSeries = gulp . series ( lintCss , transpileLess ) ;
214
+ const buildAotSeries = gulp . series ( inlineTemplate , transpileAot , postTranspile ) ;
215
+ const transpileSeries = gulp . series ( inlineTemplate , transpile , postTranspile ) ;
256
216
const copyExamplesSeries = gulp . series ( copyExamples ) ;
257
217
const copyPkgFilesSeries = gulp . series ( copyPkgFiles ) ;
258
218
259
- const buildSeries = gulp . series ( inlineTemplate , transpile , buildCssSeries , buildLessSeries , copyPkgFilesSeries ) ;
219
+ const buildSeries = gulp . series ( transpileSeries , buildCssSeries , copyPkgFilesSeries ) ;
260
220
const updateWatchDistSeries = gulp . series ( buildSeries , updateWatchDist ) ;
261
221
const watchSeries = gulp . series ( updateWatchDistSeries , watch ) ;
262
222
263
223
gulp . task ( 'build' , buildSeries ) ;
264
224
gulp . task ( 'build-aot' , buildAotSeries ) ;
265
225
gulp . task ( 'build-css' , buildCssSeries ) ;
266
- gulp . task ( 'build-less' , buildLessSeries ) ;
267
226
gulp . task ( 'copy-examples' , copyExamplesSeries ) ;
268
227
gulp . task ( 'copy-pkg-files' , copyPkgFilesSeries ) ;
269
228
gulp . task ( 'watch' , watchSeries ) ;
0 commit comments