-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write inline js in gulpfile.js instead of external file #21
Comments
Yes we want that! ;-P |
I think to resolve it you can use:
|
I just implemented something like this. In my code the pipeline inside const { src, dest } = require('gulp');
const tsify = require('tsify');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const inlinesource = require('gulp-inline-source');
function tsLoader(sourceFile) {
return new Promise((resolve, reject) => {
browserify([sourceFile.filepath])
.plugin(tsify)
.bundle()
.on('error', (error) => {
console.log(error.toString());
return reject(error);
})
.pipe(source())
.pipe(buffer())
.on('error', (error) => {
content.log(error.toString());
return reject(error);
})
.on('data', (file) => {
if (file.isBuffer()) {
sourceFile.content = file.contents;
return resolve();
} else {
return reject('Unsupported record type');
}
});
});
}
function build() {
return src(htmlFile)
.pipe(inlinesource({
attribute: false,
handlers: [
(source, context) => {
if (source.format === 'ts') {
return tsLoader(source);
}
}
],
}))
.pipe(dest(builddir));
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for your plugin. It's really good.
That would be nice if we could write our scripts at the gulpfile.js without external file. Very useful for some apps that need domain for ajax.
Eq. gulpfile.js:
Would output:
The text was updated successfully, but these errors were encountered: