Tools: how to use 'redirects'?

Created on 13 Jan 2016  ยท  5Comments  ยท  Source: Polymer/tools

ERROR finding /markdown-editor/app/bower_components/polymer/polymer.html

the file is actually in /markdown-editor/bower_components/polymer/polymer.html

what should i do to let it redirect app/bower_components to bower_components?

thanks a lot

bundler Low Question wontfix

All 5 comments

Folder structure:

.
โ”œโ”€โ”€ bower_components
โ”‚ย ย  โ”œโ”€โ”€ font-roboto
โ”‚ย ย  โ”œโ”€โ”€ iron-flex-layout
โ”‚ย ย  โ”œโ”€โ”€ paper-styles
โ”‚ย ย  โ”œโ”€โ”€ polymer
โ”‚ย ย  โ””โ”€โ”€ webcomponentsjs
โ””โ”€โ”€ src
    โ”œโ”€โ”€ tango-palette.html
    โ””โ”€โ”€ vca-theme.html
gulp.task('build', () => {
  const redirects = fs.readdirSync('bower_components').filter(file => {
    return fs.statSync(path.join('bower_components', file)).isDirectory();
  }).map(folder => `${__dirname}/${folder}|${__dirname}/bower_components/${folder}`);

  return gulp.src('src/vca-theme.html')
    .pipe($.vulcanize({
      stripComments: true,
      inlineCss: true,
      inlineScripts: true,
      redirects: [
        `${__dirname}/polymer|${__dirname}/bower_components/polymer`,
        `${__dirname}/paper-styles|${__dirname}/bower_components/paper-styles/`
      ]
    }))
    .pipe(gulp.dest('dist'));
});

@mattyclarkson Can you provide a vanilla (non-gulp) example? I don't see how the const redirects are even used in this code, and I still havent figured out how to use redirects -- the documentation says the first component before | needs to be a URI but you example doesn't indicate this. Too confusing

Here's what I wound up with

var Vulcanize = require('vulcanize');
var crisper = require('crisper');
var fs = require('fs');
var path = require('path');

const target = 'demo/index.html';

const redirects = fs.readdirSync('bower_components').filter(file => {
    return fs.statSync(path.join('bower_components', file)).isDirectory();
}).map(folder => `/${folder}/|/bower_components/${folder}/`);

var vulcan = new Vulcanize({
    abspath: './',
    inlineScripts: true,
    inlineCss: true,
    stripComments: true,
    redirects: redirects,
});

vulcan.process(target, (err, html) => {
    if (err) {
        // error
    } else {
        var output = crisper({
            source: html,
            jsFileName: 'build.js',
        });
        fs.writeFile('app/build.html', output.html, 'utf-8');
        fs.writeFile('app/build.js', output.js, 'utf-8');
    }
});

This also works fine:

gulp.task('vulcanize', function(done) {
  gulp.src('app/index.html')
    .pipe(vulcanize({
      abspath: '',
      excludes: [],
      redirects: [
        '/bower_components|./bower_components',
        '/elements|./app/elements',
        '/styles|./app/styles',
      ],
      stripExcludes: false
    }))
    .pipe(gulp.dest('dist'));
});

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justinfagnani picture justinfagnani  ยท  4Comments

dilansankalpa picture dilansankalpa  ยท  3Comments

Westbrook picture Westbrook  ยท  4Comments

rasto68 picture rasto68  ยท  4Comments

idoshamun picture idoshamun  ยท  3Comments