Last active
November 4, 2020 18:02
-
-
Save ricardobeat/606859bfcbfbdf84a030ec32382fe202 to your computer and use it in GitHub Desktop.
Taks sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { task, read, write } = require('taks') | |
const _postcss = require('postcss') | |
const _rollup = require('rollup') | |
const _uglify = require('uglify-es') | |
const postcss = task.plugin(async function (input, output, options) { | |
let opts = Object.assign({ from: undefined, plugins: [] }, options) | |
let src = await read(input) | |
let { css } = await _postcss(opts.plugins).process(src, opts) | |
return write(output, css) | |
}) | |
const rollup = task.plugin(async function (input, output, options) { | |
let opts = Object.assign({ file: output, format: 'iife' }, options) | |
let bundle = await _rollup.rollup({ input }) | |
return bundle.write(opts) | |
}) | |
const uglify = task.plugin(async function (input, output, options) { | |
let src = await read(input) | |
let { code } = _uglify.minify({ 'src.js': src }, options) | |
return write(output, code) | |
}) | |
// ----------------------------------------------------------------------------- | |
const cssConfig = require('./postcss.config.js') | |
const cssMinify = { plugins: ['cssnano'] } | |
task('styles:main', async function () { | |
await postcss('./lib/main.css', './dist/main.css', cssConfig) | |
}) | |
task('styles:compat', async function () { | |
await postcss('./lib/main.css', './dist/main.css', cssConfig) | |
}) | |
task('styles:min', async function () { | |
let conf = { plugins: ['cssnano'] } | |
await postcss('./dist/main.css', './dist/main.min.css', conf) | |
await postcss('./dist/compat.css', './dist/compat.min.css', conf) | |
}) | |
task('styles', async function () { | |
await task.parallel(['styles:main', 'styles:compat']) | |
await task.run('styles:min') | |
}) | |
task('scripts', async function () { | |
await rollup('./lib/main.js', './dist/main.js') | |
await uglify('./dist/main.js', './dist/main.min.js') | |
}) | |
task('build', async function () { | |
task.parallel(['styles', 'scripts']) | |
}) | |
task.run(process.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment