1.22.3 • Published 1 year ago

@swissquote/crafty-runner-rollup v1.22.3

Weekly downloads
83
License
Apache-2.0
Repository
github
Last release
1 year ago

Description

rollup.js is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application.

rollup.js works well with libraries because it's able to output files with EcmaScript 2015 exports which allow for advanced tree shaking.

The rollup.js integration is experimental and has some issues that are known and some that are not pinpointed yet.

TOC

Features

  • Bundle your JavaScript using EcmaScript 2015 imports or commonjs imports
  • Your code is Uglified after compilation.
  • Configurable output formats
  • Watch mode, re-compiles your files on changes

Options

We don't provide any option to configure rollup.js outside bundles, but as crafty.config.js is considered as a preset, you can define the rollup override method in your configuration file and change the configuration to your needs.

Check the Extending the configuration section below for more information on that.

Bundle Options

The rollup.js preset is compatible with our Babel and TypeScript

OptionTypeOptional ?Description
formatstringYesDefine the output format can be any of amd, iife, cjs, es or umd. Defaults to es.
externalsstring[]YesExtends the list of provided libraries (Webpack understands both globs and strings, rollup.js doesn't understand globs)
inlineRuntimebooleanYesDo we inline the @babel/runtime ? Read below for details and implication

inlineRuntime / put @babel/runtime inline or keep it as imports

Default: true when nothing is specified, and to false when a dependency to @babel/runtime is found.

When compiling newer EcmaScript to older versions, some helper functions can be needed to make it work. For example functions to create classes, rest, spread, etc...

These helpers are quite small, however, if you are creating a library which will be included in another project, your bundle might end up containing the library along with the copies that the final project will contain as well.

A way to reduce this cost is instead of having these helpers inline is to keep them as imports.

// This
function _classCallCheck(instance, Constructor) {
  /* */
}
function _defineProperties(target, props) {
  /* */
}
function _createClass(Constructor, protoProps, staticProps) {
  /* */
}

// Becomes
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";

The way to do this is by adding a dependency to @babel/runtime in your project's package.json.

If for some reason you need a dependency to @babel/runtime but still wish helpers to be inline, you can force it with inlineRuntime: true.

Extending the configuration

Each preset and crafty.config.js can define the rollup(crafty, bundle, rollupConfig) function to override rollup.js' configuration.

module.exports = {
  /**
   * Represents the extension point for rollup.js configuration
   * @param {Crafty} crafty - The instance of Crafty.
   * @param {Object} bundle - The bundle that is being prepared for build (name, input, source, destination)
   * @param {Object} rollupConfig - The current rollup.js configuration (input, output, watch)
   */
  rollup(crafty, bundle, rollupConfig) {
    // Mutate any of rollupConfig.input, rollupConfig.output or rollupConfig.watch to your liking
  }
};

The full list of available configuration option is available on the official website.

The difference with the official configuration is how plugins are handled. The section below explains how plugins are configured.

Adding / modifying plugins

In rollup.js, plugins are functions that are called with their options.

As we want to be able to override those options during the preparation phase of the runner, those plugins are presented in the following way :

Here is an example of how the rollup-plugin-eslint is integrated into rollup.js .

const rollupEslint = require("rollup-plugin-eslint");

module.exports = {
  /**
   * Represents the extension point for rollup configuration
   * @param {Crafty} crafty - The instance of Crafty.
   * @param {Object} bundle - The bundle that is being prepared for build (name, input, source, destination)
   * @param {string} rollupConfig - The current rollup configuration (input, output, watch)
   */
  rollup(crafty, bundle, rollupConfig) {
    // rollupConfig.input.plugins is an object during preparation phase with four possible keys :
    // - plugin : the function to initialize the plugin
    // - options : A configuration object, will be passed to the function as a first parameter upon initialization
    // - weight : (optional) The weight of the plugin, used to define the order in which the plugins are run (A weight of 0 is applied if this key is omitted)
    // - init : (optional) A function that Returns an instance of the plugin. The default is : `(plugin) => plugin.plugin(plugin.options)`

    rollupConfig.input.plugins.eslint = {
      plugin: rollupEslint,
      weight: -20,
      options: {
        ...crafty.config.eslint,
        throwOnError: crafty.getEnvironment() === "production",
        exclude: ["node_modules/**"],
        include: ["**/*.js", "**/*.jsx"]
      }
    };
  }
};

Known issues

  • If you have two bundles that run with rollup.js, if one fails, the second one stops as well.
  • ESLint stops linting after the first file in error, this shouldn't be the case.
1.22.0-alpha.3

1 year ago

1.22.0-alpha.5

1 year ago

1.22.0-alpha.4

1 year ago

1.22.0

1 year ago

1.22.0-alpha.6

1 year ago

1.22.3

1 year ago

1.22.1

1 year ago

1.22.2

1 year ago

1.22.0-alpha.2

1 year ago

1.22.0-alpha.1

1 year ago

1.21.0

1 year ago

1.21.1

1 year ago

1.21.0-alpha.2

1 year ago

1.21.0-alpha.1

1 year ago

1.20.0-alpha.4

2 years ago

1.20.0

2 years ago

1.20.0-alpha.2

2 years ago

1.20.0-alpha.3

2 years ago

1.20.0-alpha.1

2 years ago

1.19.0

2 years ago

1.19.1

2 years ago

1.18.5-alpha.3

2 years ago

1.18.5-alpha.4

2 years ago

1.18.5-alpha.2

2 years ago

1.18.5-alpha.1

2 years ago

1.18.1

2 years ago

1.18.0

2 years ago

1.18.4

2 years ago

1.18.3

2 years ago

1.18.2

2 years ago

1.17.3-alpha.25

2 years ago

1.17.3-alpha.26

2 years ago

1.17.3-alpha.23

2 years ago

1.17.3-alpha.24

2 years ago

1.17.3-alpha.21

2 years ago

1.17.3-alpha.22

2 years ago

1.17.3-alpha.20

2 years ago

1.17.3-alpha.18

2 years ago

1.17.3-alpha.19

2 years ago

1.17.3-alpha.17

2 years ago

1.18.1-alpha.2

2 years ago

1.18.1-alpha.3

2 years ago

1.18.1-alpha.1

2 years ago

1.17.3-alpha.3

2 years ago

1.17.3-alpha.4

2 years ago

1.17.3-alpha.2

2 years ago

1.17.3-alpha.7

2 years ago

1.17.3-alpha.8

2 years ago

1.17.3-alpha.5

2 years ago

1.17.3-alpha.6

2 years ago

1.17.3-alpha.16

2 years ago

1.17.3-alpha.14

2 years ago

1.17.3-alpha.9

2 years ago

1.17.3-alpha.15

2 years ago

1.17.3-alpha.12

2 years ago

1.17.3-alpha.10

2 years ago

1.17.3-alpha.11

2 years ago

1.17.3-alpha.1

2 years ago

1.17.2

3 years ago

1.17.0-beta.1

3 years ago

1.17.1

3 years ago

1.16.3

3 years ago

1.16.1

3 years ago

1.16.1-beta.1

3 years ago

1.16.0

3 years ago

1.16.0-beta.5

3 years ago

1.16.0-beta.6

3 years ago

1.16.0-beta.3

3 years ago

1.16.0-beta.4

3 years ago

1.16.0-beta.2

3 years ago

1.16.0-beta.1

3 years ago

1.16.0-beta.0

3 years ago

1.15.0-beta.0

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.14.0-beta.8

3 years ago

1.14.0-beta.7

3 years ago

1.14.0-beta.3

3 years ago

1.13.7

4 years ago

1.13.6-beta.0

4 years ago

1.14.0-beta.2

4 years ago

1.14.0-beta.1

4 years ago

1.13.5

4 years ago

1.13.5-beta.1

4 years ago

1.13.5-beta.0

4 years ago

1.13.2

4 years ago

1.13.4

4 years ago

1.13.3

4 years ago

1.13.0-beta.2

4 years ago

1.13.0

4 years ago

1.13.0-beta.1

4 years ago

1.13.0-beta.0

4 years ago

1.12.1-beta.2

4 years ago

1.12.0

4 years ago

1.12.0-beta.0

4 years ago

1.11.1

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.0

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.1-beta.0

5 years ago

1.4.0

5 years ago

1.3.1-alpha.27

5 years ago

1.3.0

6 years ago

1.2.2-alpha.22

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago