blendid
blendid copied to clipboard
Custom Dest Path
Hello, thank you for writing this tools. I found it very useful on my rails app. However, I found a difficult case for integrating gulp task. I want to add service worker by sw-precache.
Is it possible to use different PATH_CONFIG.dest?
I have path-config.json like this
{
"src": "./assets",
"dest": "./public/assets",
...
}
While, I want to add gulp task to generate service worker, and it has to be on ./public dir.
additionalTasks: {
initialize(gulp, PATH_CONFIG, TASK_CONFIG) {
gulp.task('generate-sw', function(callback) {
var swPrecache = require('sw-precache');
var rootDir = PATH_CONFIG.dest; // I want it to be ./public
swPrecache.write(`${rootDir}/service-worker.js`, {
staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'],
stripPrefix: rootDir
}, callback);
});
},
development: {
prebuild: null,
postbuild: ['generate-sw'],
},
production: {
prebuild: null,
postbuild: ['generate-sw'],
}
}
I've tried to directly change var rootDir = "./public" but blendid cannot build it on that dir.
Thanks.
@hezbymuhammad another aspect worth trying is to create a separate item in the PATH_CONFIG for your public assets for routing. although it is heavy-handed it may solve the problem you are encountering.
something like this:
{
"src": "./assets",
"dest": "./public/assets",
"destParent": "./public",
...
}
this way you can use var rootDir = PATH_CONFIG.destParent; in your additionalTask configuration.
disclaimer: i have not tested this personally so it may need more thinking or configuration
@hezbymuhammad were you able to find a solution to this?
@olets sorry for late update, but unfortunately I ended up giving up on this since proposed solution didn't work 🙏
It might be I was not implementing it correctly, but I couldn't use destParent.