Example #1
0
module.exports = function (sandbox) {
  var tmpdir = sandbox.tmpdir
    , timer   = stopwatch()
    , N = sandbox.N
    , environment;


  //
  // set custom logger for the Mincer
  //

  Mincer.logger.use(N.logger);


  environment = new Mincer.Environment(tmpdir);

  //
  // set mincer cache dir
  //
  environment.cache = new Mincer.FileStore(N.config.options.cache_dir);

  //
  // rebuild assets on config change:
  //
  // - track `bundle.yml` in ALL apps
  //
  environment.version = md5(JSON.stringify(sandbox.config.packages));

  //
  // Enable autoprefixer
  //
  Mincer.Autoprefixer.configure([
    'android >= 2.2',
    'bb >= 7',
    'chrome >= 26',
    'ff >= 17',
    'ie >= 8',
    'ios >= 5',
    'opera >= 12',
    'safari >= 5'
  ]);
  environment.enable("autoprefixer");

  //
  // Provide some helpers to EJS and Stylus
  //

  environment.ContextClass.defineAssetPath(function (pathname, options) {
    // this throws exception with details, if asset not exists
    var resolvedPath = this.resolve(pathname);

    sandbox.assets.used.push(resolvedPath);
    //  console.log(pathname)

    var asset = environment.findAsset(resolvedPath, options);
    return !asset ? null : ("/assets/" + asset.digestPath);
  });

  //
  // Add jetson serializer helper
  //

  environment.registerHelper('jetson', require('../../jetson').serialize);


  sandbox.assets = {
    environment:  environment,
    // holds list of assets to be bundled by mincer
    files:        [],
    // track assets, requested via helpers on compile,
    // used to check integrity in manifest
    //
    // (!!!) Note, that does not track helpers for cached
    // assets (from previous builds) and for runtime calls
    // from .jade templates.
    used:         []
  };

  N.logger.info('Initialized assets manager %s', timer.elapsed);
};
Example #2
0
module.exports = function (sandbox) {
  var tmpdir = sandbox.tmpdir
    , timer   = stopwatch()
    , N = sandbox.N
    , environment;


  //
  // set custom logger for the Mincer
  //

  Mincer.logger.use(N.logger);


  environment = new Mincer.Environment(tmpdir);

  //
  // set mincer cache dir
  //
  environment.cache = new Mincer.FileStore(N.config.options.cache_dir);


  //
  // Enable autoprefixer
  //
  Mincer.Autoprefixer.configure([
    'android >= 2.2',
    'bb >= 7',
    'chrome >= 26',
    'ff >= 17',
    'ie >= 8',
    'ios >= 5',
    'opera >= 12',
    'safari >= 5'
  ]);
  environment.enable("autoprefixer");


  //
  // Provide some helpers to EJS and Stylus
  //

  environment.ContextClass.defineAssetPath(function (pathname, options) {
    var asset = environment.findAsset(pathname, options);
    return !asset ? null : ("/assets/" + asset.digestPath);
  });

  //
  // Add jetson serializer helper
  //

  environment.registerHelper('jetson', require('../../jetson').serialize);


  sandbox.assets = {
    environment:  environment,
    // holds list of assets to be bundled by mincer
    files:        []
  };

  N.logger.info('Initialized assets manager %s', timer.elapsed);
};
Example #3
0
 [].concat(options.enable).forEach(function (configuration) {
   environment.enable(configuration);
 });
Example #4
0
  locales: ['ru', 'en'],
  defaultLocale: 'ru',
  // cookieName: "locale"
});

app.use((req, res, next) => {
  // req.i18n.setLocaleFromQuery();
  // req.i18n.setLocaleFromCookie();
  req.i18n.setLocale('ru');
  next();
});

Mincer.logger.use(console);

let environment = new Mincer.Environment();
environment.enable('source_maps');
environment.enable('autoprefixer');
environment.appendPath('app/assets/javascripts');
environment.appendPath('app/assets/stylesheets');
environment.appendPath('node_modules');
environment.appendPath('bower_components');

app.use('/assets', Mincer.createServer(environment));
app.use(rollbar.errorHandler(process.env.ROLLBAR_BACKEND_TOKEN));

if (process.env.NODE_ENV === 'production') {
  environment.cache = new Mincer.FileStore(path.join(__dirname, 'cache'));
  environment.jsCompressor = 'uglify';
  environment.cssCompressor = 'csswring';
  environment = environment.index;
}
Example #5
0
  var mince = function (src, options) {
    var environment, asset, err;

    function configureEngine(name) {
      var engine = Mincer[name + 'Engine'] || Mincer[name],
        opts = options.engines[name];
      if (!engine || typeof engine.configure !== 'function') {
        grunt.fail.warn('Invalid Mincer engine ' + name.cyan);
      }
      engine.configure(opts);
    }

    options.configure(Mincer);

    environment = new Mincer.Environment(process.cwd());

    if (options.enable) {
      [].concat(options.enable).forEach(function (configuration) {
        environment.enable(configuration);
      });
    }

    [].concat(options.include).forEach(function (include) {
      environment.appendPath(include);
    });
    environment.appendPath(path.dirname(src));
    environment.appendPath(process.cwd());

    Object.keys(options.helpers).forEach(function (key) {
      // Create a bound function which has access to the current Mincer.Environment
      var helper = options.helpers[key].bind({
        environment: environment
      });
      environment.registerHelper(key, helper);
    });

    if (Object.keys(options.engines).some(configureEngine)) {
      return;
    }

    if (options.jsCompressor) {
      environment.jsCompressor = options.jsCompressor;
    }

    if (options.cssCompressor) {
      environment.cssCompressor = options.cssCompressor;
    }

    if (options.manifestPath && options.manifestPath.length > 0) {
      var resolvedAssets = src.map(function(filepath) {
        return logicalAssetName(environment, filepath);
      });

      if ((options.manifestOptions.sourceMaps !== null) && options.manifestOptions.sourceMaps) {
        environment.enable('source_maps');
      }

      var manifest = new Mincer.Manifest(environment, options.manifestPath);
      return manifest.compile(resolvedAssets, options.manifestOptions);
    }

    asset = environment.findAsset(src);
    if (!asset) {
      grunt.fail.warn('Cannot find logical path ' + src.cyan);
    }
    return asset;
  };