vigetlabs / blendid

A delicious blend of gulp tasks combined into a configurable asset pipeline and static site builder
MIT License
4.97k stars 683 forks source link

Custom Dest Path #542

Open hezbymuhammad opened 6 years ago

hezbymuhammad commented 6 years ago

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.

benjtinsley commented 6 years ago

@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

olets commented 5 years ago

@hezbymuhammad were you able to find a solution to this?

hezbymuhammad commented 5 years ago

@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.