These are chat archives for brunch/brunch

14th
Dec 2016
Mauro Oviedo
@moviedo
Dec 14 2016 18:43
anyone know how to work with npm static files
npm: {
    styles: {
      bootstrap: ['dist/css/bootstrap.css']
    },
    static: [
      "bootstrap/dist/fonts/glyphicons-halflings-regular.eot",
      "bootstrap/dist/fonts/glyphicons-halflings-regular.svg",
      "bootstrap/dist/fonts/glyphicons-halflings-regular.ttf",
      "bootstrap/dist/fonts/glyphicons-halflings-regular.woff",
      "bootstrap/dist/fonts/glyphicons-halflings-regular.woff2"
    ]
  },
the static section above doesn't seem to be working correctly for me in brunch v2.9.1
Colin Bate
@colinbate
Dec 14 2016 18:46
I don't think it is meant to be used to copy files over, reading the docs it sounds like they get pulled into your js bundles.
Mauro Oviedo
@moviedo
Dec 14 2016 18:46
ah
Colin Bate
@colinbate
Dec 14 2016 18:46
But I've not used it, at least not that I recall :)
Mauro Oviedo
@moviedo
Dec 14 2016 18:46
does override work for package.json like it does for bower @colinbate
by any chance would u know?
if not, i guess i'll just use bower to get the font files
Colin Bate
@colinbate
Dec 14 2016 18:49
I've always used something like copyfilemon-brunch to copy over the static files like that
Mauro Oviedo
@moviedo
Dec 14 2016 18:50
yeah, i used to use after-brunch, but then i learned about onCompile
it's very useful
var shell = require('shelljs');
...
conventions: {
        assets: function (path) {
            /**
             * Loops every path and returns path|true|false according what we need
             * @param   path    file or directory's path
             * @returns path    if it is a directory
             *          true    if it fit with the regular expression
             *          false   otherwise
             *
             */
            if (/\/$/.test(path)) return path;
            // RegExp for anything we need
            return /assets[\\/]/.test(path) || /.*(?:\.eot|\.svg|\.ttf|\.woff2|\.woff)/.test(path);
        }
    },
...
hooks: {
    onCompile: function (generatedFiles, changedAssets) {
      // update files only if assets files change
      if (!changedAssets.length) {
        return;
      }

      // run only if bootstrap files change
      var changed = changedAssets.some(function (asset) {
        return asset.path.search('bower_components/bootstrap') != -1;
      });

      if (!changed) return;

      // move bootstrap font files
      shell.mv(public_dir + '/bootstrap/dist/fonts/*', public_dir + '/fonts');
      shell.rm('-rf', public_dir + '/bootstrap');
    }
  },
works very nicely
but this was in brunch v2.8.2