Created
April 15, 2019 10:04
-
-
Save jahudka/b233306a146b9e4bf79aac16bd3b3b7f to your computer and use it in GitHub Desktop.
Nittro with WebPack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'); | |
const ternary = require('ternary-stream'); | |
const nittro = require('gulp-nittro'); | |
const webpack = require('webpack-stream'); | |
const uglify = require('gulp-uglify'); | |
const concat = require('gulp-concat'); | |
const sourcemaps = require('gulp-sourcemaps'); | |
const builder = new nittro.Builder({ | |
base: { /* ... */ }, | |
extras: { /* ... */ }, | |
libraries: { | |
js: ["./src/services.js"], // path to the services entry point | |
}, | |
bootstrap: { | |
services: { // as usual | |
"myFirstService": "MyFirstService()!", | |
"mySecondService": "MySecondService()!" | |
} | |
}, | |
stack: true | |
}); | |
gulp.task('js', () => { | |
return nittro('js', builder) | |
.pipe(sourcemaps.init({ loadMaps: true })) | |
.pipe(ternary( | |
// this should be a function that returns true | |
// only for the services entrypoint: | |
f => /\/src\/services\.js$/.test(f.path), | |
// which will then be processed by webpack: | |
webpack() | |
)) | |
.pipe(ternary( | |
// this saves build time by not uglifying | |
// already minified files: | |
f => !/\.min\.js$/.test(f.path), | |
uglify({ compress: true, mangle: false }) | |
)) | |
.pipe(concat('build.min.js')) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('public/js')); | |
}); | |
// similar task might be made for CSS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define a single entry point for all your services | |
import './myFirstService'; | |
import './mySecondService'; | |
// ... etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment