1.0.2 • Published 4 years ago

@wok-cli/task-scripts v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Scripts Task

Sharable tasks for scripts.

By default the task just copies scripts from source to destination. Use one of the hooks to transform the source code.

Installation

This task requires @wok-cli/core as peer dependency.

npm i @wok-cli/core @wok-cli/task-scripts --save-dev

Parameters

parametertypedefaultnote
srcstringstring[]Globs source files (1)
deststringDestination folder (1)
sourcemapsstringbooleanWrite sourcemaps. See here for details(2)
hook:(*)objectHooks configuration parameters (see below)
  1. Supports environment templates.
  2. Defaults to the value of $.env.sourcemaps.

Hooks

nametypedescription
prelazypipeExecuted before transform hook
transformlazypipeUse this hook to transform source code with tools like Babel
postlazypipeExecuted just before writing the file to disk

Example

const $ = require('@wok-cli/core');
const scripts = require('@wok-cli/task-scripts');

exports.scripts = $.task(scripts, {
  src: ['src/assets/js/**/*.js'],
  dest: 'public/assets/js',
});

Usage with gulp-babel

const $ = require('@wok-cli/core');
const scripts = require('@wok-cli/task-scripts');
const babel = require('gulp-babel');

const scriptsTask = $.task(scripts, {
  src: ['src/assets/js/**/*.js'],
  dest: 'public/assets/js',
});

scriptsTask.tap('transform', 'babel', (lazypipe) => {
  return lazypipe.pipe(
    babel,
    {
      // babel configuration here...
    },
  );
});

exports.scripts = scriptsTask;