Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve this ? #362

Closed
anjkt opened this issue Jan 3, 2018 · 4 comments
Closed

How to solve this ? #362

anjkt opened this issue Jan 3, 2018 · 4 comments

Comments

@anjkt
Copy link

anjkt commented Jan 3, 2018

screenshot 101
I m getting this error while hitting npm run build

@ozasadnyy
Copy link
Member

it's gulp related issue: gulpjs/gulp#2065
Also, we had such issue here: #356

@anjkt
Copy link
Author

anjkt commented Jan 3, 2018

I had fixed up the above Please Help me for this I am getting this error again

@anjkt
Copy link
Author

anjkt commented Jan 3, 2018

'use strict';

const del = require('del');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const cssSlam = require('css-slam').gulp;
const mergeStream = require('merge-stream');
const polymerBuild = require('polymer-build');
const browserSync = require('browser-sync').create();
const history = require('connect-history-api-fallback');

const logging = require('plylog');
// logging.setVerbose();

const config = {
polymerJsonPath: './polymer.json',
build: {
rootDirectory: 'build',
bundled: true
},
swPrecacheConfigPath: './sw-precache-config.js',
templateData: [
'data/hoverboard.config',
'data/resources'
],
tempDirectory: '.temp'
};
const swPrecacheConfig = require(config.swPrecacheConfigPath);
const polymerJson = require(config.polymerJsonPath);
const buildPolymerJson = {
entrypoint: prependPath(config.tempDirectory, polymerJson.entrypoint),
shell: prependPath(config.tempDirectory, polymerJson.shell),
fragments: polymerJson.fragments.reduce((res, el) => [...res, prependPath(config.tempDirectory, el)], []),
sources: polymerJson.sources.reduce((res, el) => [...res, prependPath(config.tempDirectory, el)], []),
extraDependencies: polymerJson.extraDependencies
};

const normalize = require('./gulp-tasks/normalize.js');
const template = require('./gulp-tasks/template.js');
const images = require('./gulp-tasks/images.js');
const html = require('./gulp-tasks/html.js');

function build() {
return new Promise(resolve => {
let polymerProject = null;
let sourcesStreamSplitter = new polymerBuild.HtmlSplitter();
let dependenciesStreamSplitter = new polymerBuild.HtmlSplitter();

console.log(`Deleting ${config.build.rootDirectory} and ${config.tempDirectory} directories...`);

del([config.build.rootDirectory, config.tempDirectory])
  .then(() => {
    console.log(`Compiling template...`);

    const compileStream = template.compile(config, polymerJson)
      .on('end', () => {
        polymerProject = new polymerBuild.PolymerProject(buildPolymerJson);
      });
    return waitFor(compileStream);
  })
  .then(() => {
    console.log(`Polymer building...`);

    const sourcesStream = polymerProject.sources()
      .pipe(gulpif(/\.(png|gif|jpg|svg)$/, images.minify()))
      .pipe(sourcesStreamSplitter.split())
      // splitHtml doesn't split CSS https://github.com/Polymer/polymer-build/issues/32
      .pipe(gulpif(/\.js$/, uglify()))
      .pipe(gulpif(/\.(html|css)$/, cssSlam()))
      .pipe(gulpif(/\.html$/, html.minify()))
      .pipe(sourcesStreamSplitter.rejoin());

    const dependenciesStream = polymerProject.dependencies()
      .pipe(dependenciesStreamSplitter.split())
      .pipe(gulpif(/\.js$/, uglify()))
      .pipe(gulpif(/\.(html|css)$/, cssSlam()))
      .pipe(gulpif(/\.html$/, html.minify()))
      .pipe(dependenciesStreamSplitter.rejoin());

    let buildStream = mergeStream(sourcesStream, dependenciesStream)
      .once('data', () => {
        console.log('Analyzing and optimizing...');
      });

    buildStream = buildStream.pipe(polymerProject.bundler());
    buildStream = buildStream.pipe(gulp.dest(config.build.rootDirectory));
    return waitFor(buildStream);
  })
  .then(() => {
    console.log('Generating the Service Worker...');

    return polymerBuild.addServiceWorker({
      project: polymerProject,
      buildRoot: prependPath(config.build.rootDirectory, config.tempDirectory).replace('\\', '/'),
      bundled: config.build.bundled,
      swPrecacheConfig
    });
  })
  .then(() => {
    console.log('Normalizing...');

    const normalizeStream = normalize(config)
      .on('end', () => {
        del([prependPath(config.build.rootDirectory, config.tempDirectory)])
      });

    return waitFor(normalizeStream);
  })
  .then(() => {
    return gulp.src(prependPath(config.build.rootDirectory, 'service-worker.js'))
      .pipe(uglify())
      .pipe(gulp.dest(config.build.rootDirectory));
  })
  .then(() => {
    console.log('Build complete!');
    resolve();
  });

});
}

function waitFor(stream) {
return new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
});
}

function copyAndReload(file) {
const dest = prependPath(config.tempDirectory, file.substring(0, file.lastIndexOf('/')))

gulp.src(file).pipe(gulp.dest(dest));

browserSync.reload();
}

function reload(done) {
browserSync.reload();
done();
}

function compileTemplate() {
return del([config.tempDirectory])
.then(() => {
return waitFor(template.compile(config, polymerJson));
});
}

function prependPath(pre, to) {
return ${pre}/${to};
}

gulp.task('default', build);

gulp.task('serve', gulp.series(compileTemplate, () => {
browserSync.init({
logPrefix: 'Hoverboard',
notify: false,
server: {
baseDir: [config.tempDirectory, './'],
middleware: [history()]
}
});

gulp.watch([
'data//*.{markdown,md}',
'images/
/*.{png,gif,jpg,svg}',
]).on('change', copyAndReload);

gulp.watch([
'data//*.json',
'scripts/
/.js',
'src/**/
.html',
'./index.html',
'manifest.json'
], gulp.series(compileTemplate, reload));
}));

@ozasadnyy
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants