Вход Регистрация
Файл: flyfile.js
Строк: 106
<?php
var browserSync = require('browser-sync');

var 
isProd = false;
var 
isWatch = false;
var 
isServer = false;

var 
dest = 'dist';
var 
src = {
    
scripts: 'src/javascript/**/*.js',
    
styles: 'src/styles/**/*.{sass,scss}',
    
images: 'src/images/**/*.{jpg,png,svg}',
    
html: ['src/htdocs/*.html', 'src/htdocs/examples/*.html'],
    
vendor: 'src/javascript/_lib/*.js',
    
extras: ['src/htdocs/data/*']
};

exports.default = function * () {
    
/** @desc Default Task: `watch` */
    
yield this.start('watch');
};

exports.watch = function * () {
    
/** @desc Main Task: Starts a server & Recompiles files on change */
    
isWatch = true;
    
isProd = false;

    yield 
this.start('clean');
    yield 
this.watch(src.scripts, ['lint', 'scripts']);
    yield 
this.watch(src.styles, 'styles');
    yield 
this.watch(src.images, 'images');
    yield 
this.watch(src.html, 'html');
    yield 
this.start(['vendor', 'extras', 'serve']);
};

exports.build = function * () {
    
/** @desc Main Task: Build the production files */
    
isProd = true;
    
isWatch = false;

    yield 
this.start('clean');
    yield 
this.start(['lint', 'html', 'extras']);
    yield 
this.start(['images', 'styles', 'scripts', 'vendor']);
};

// ###
// # Tasks
// ###

exports.clean = function * () {
    
/** @desc Delete all files in the `dist` directory */
    
yield this.clear(dest);
};

exports.lint = function * () {
    
/** @desc Lint javascript files */
    
yield this.source(src.scripts).xo({
        
env: 'browser',
        
globals: ['classie', 'Parallax'],
        
ignore: [src.vendor],
        
rules: {
            
curly: 0,
            
'one-var': 0,
            
'xo/filename-case': 0
        
}
    });
};

exports.images = function * () {
    
/** @desc Compress and copy all images to `dist` */
    
yield this
        
.source(src.images)
        .
target(dest + '/img', {depth: 1});

    
reload();
};

exports.html = function * () {
    
/** @desc Compile all HTML files with Nunjucks. Will run `htmlmin` during `build` task. */
    
yield this.source(src.html)
        .
nunjucks({
            
base: 'src/htdocs'
        
})
        .
target(dest, {depth: 0});

    return 
isProd ? yield this.start('htmlmin') : reload();
};

exports.htmlmin = function * () {
    
/** @desc Minify all HTML files already within `dist`. Production only */
    
yield this.source(dest + '/*.html')
        .
htmlmin({
            
removeComments: true,
            
collapseWhitespace: true,
            
collapseBooleanAttributes: true,
            
removeAttributeQuotes: true,
            
removeRedundantAttributes: true,
            
removeEmptyAttributes: true,
            
removeScriptTypeAttributes: true,
            
removeStyleLinkTypeAttributes: true,
            
removeOptionalTags: true
        
})
        .
target(dest);
};

exports.vendor = function * () {
    
/** @desc Copy the Vendor JS files */
    
yield this.source(src.vendor)
        .
target(dest + '/js/vendor');
}

exports.extras = function * () {
    
/** @desc Copy extra fiels to `dest` root */
    
yield this.source(src.extras)
        .
target(dest);
}

exports.scripts = function * () {
    
/** @desc Compile javascript files with Browserify. Will run `uglify` during `build` task.  */
    
yield this
        
.source('src/javascript/main.js')
        .
browserify()
        .
concat('bee3D.js')
        .
target(dest + '/js');

    return 
isProd ? yield this.start('uglify') : reload();
};

exports.uglify = function * () {
    
/** @desc Minify all javascript files already within `dist` */
    
yield this.source(dest + '/js/*.js')
        .
uglify({
            
compress: {
                
conditionals: true,
                
comparisons: true,
                
booleans: true,
                
loops: true,
                
/* eslint camelcase: 0 */
                
join_vars: true,
                
drop_console: true
            
}
        })
        .
target(dest + '/js');
};

exports.styles = function * () {
    
/** @desc Compile and prefix stylesheets with vendor properties */
    
yield this.source([
        
'src/styles/bee3D.sass',
        
'src/styles/demo.sass',
        ])
        .
sass({
            
indentedSyntax: true,
            
outputStyle: 'compressed',
            
includePaths: ['src/styles']
        })
        .
autoprefixer({
            
browsers: [
                
'ie >= 10',
                
'ie_mob >= 10',
                
'ff >= 30',
                
'chrome >= 34',
                
'safari >= 7',
                
'opera >= 23',
                
'ios >= 7',
                
'android >= 4.4',
                
'bb >= 10'
            
]
        })
        .
target(dest + '/css');

    
reload();
};

exports.serve = function * () {
    
/** @desc Launch a local server from the `dist` directory. */
    
isServer = true;

    
browserSync({
        
notify: false,
        
logPrefix: 'Fly',
        
server: {
            
baseDir: dest
        
}
    });
};

// helper, reload browsersync
function reload() {
    if (
isWatch && isServer) {
        
browserSync.reload();
    }
}
?>
Онлайн: 2
Реклама