Git Product home page Git Product logo

rollup-worker's Introduction

rollup-worker

Based on rollup with some built-in plugins, make configure more simple and integrations.
Make .fssrc.js as the cli default config file.

Share some common plugins settings between multiple entries.

Installation

$ npm i -g rollup-worker@next

Usage

# default config: .fssrc.js
$ rb [ -c .fssrc.js ]

Example

cat .fssrc.js

const { version, name, author } = require('./package.json')
const banner = `/*! ${name} v${version} | ${license || 'MIT'} licensed. | by ${author} */`

// Optional enable some builtin plugins
const plugins = [
  'node-builtins',
  'resolve',
  'typescript',
  'commonjs',
  'babel',
  'globals',
  ['minimize', { output: { beautify: true } }] // plugin with initial options
]

module.exports = {
  plugins: {
    babel (opts, { output: { format } }) {
      const babelrc = { ...opts }
      if ([ 'es', 'cjs' ].includes(format)) {
        babelrc.comments = true
      }
      return babelrc
    },
    resolve (opts, { output: { format } }) {
      return {
        ...opts,
        preferBuiltins: false,
        customResolveOptions: {
          moduleDirectory: /min|umd|iife/.test(format) ? [ 'node_modules' ] : [ 'src' ]
        }
      }
    },
    typescript (opts) {
      return { 
        typescript: require('@allex/typescript'), // custom tsc engine
        compilerOptions: {
          newLine: "lf"
        }
      }
    },
    globals (opts, { output }) {
      return {
        ...opts,
        ...(output.format === 'es' ? {
          process: false,
          buffer: false
        } : {})
      }
    },
    minimize: { // for terser
      ie8: false
    },
    replace: {
      __VERSION__: version
    }
  },
  entry: [
    {
      input: './src/worker/index.ts',
      plugins,
      external: (id, pid, isResolved, next) => {
        return id ==== 'foo' || next(id, true)
      },
      output: [
        { format: 'es', file: 'worker.esm.js' },
        { format: 'umd', file: 'worker.js', name: 'FooWorker', banner }
      ]
    },
    {
      input: './src/app/main.ts',
      plugins: [
        ...plugins, 
        ['minimize', { output: { beautify: true } }]
      ],
      output: [
        { format: 'iife', compress: true, file: 'app/main.js', banner }
      ]
    }
  ]
}

License

MIT

rollup-worker's People

Contributors

allex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rollup-worker's Issues

外部依赖如何忽略

'os' is imported by commonjs-external-os, but could not be resolved – treating it as an external dependency
'fs' is imported by src/webpackUtils.js, but could not be resolved – treating it as an external dependency
'path' is imported by src/webpackUtils.js, but could not be resolved – treating it as an external dependency

ck-config/node_modules/happypack/lib/HappyThread.js): The argument 'path' must be a string or Uint8Array without null bytes. Received '\u0000node-globals:dirname'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.