Giter VIP home page Giter VIP logo

rollup-plugin-bundle-guard's Introduction

npm version

rollup-plugin-bundle-guard

A rollup plugin that makes sure you don't accidentally import something statically, which could have an effect on your bundle size.

How?

Tag files you want to be in the same group by adding a comment with the group name.

// rollup-plugin-bundle-guard: group=entry

If you attempt to statically import a file that is not in the same group, your build will fail with something like:

"entry.js" statically imports "load-me-dynamically.js" which is not allowed. Should it be in "entry"?

That's it!

More Detail

With strict mode disabled anything that is not assigned a group will default to the group named default, and anything is allowed to import something assigned to the default group.

Each module can only be assigned to a single group. You can however include additional groups that are allowed to import the module with the following comment:

// rollup-plugin-bundle-guard: allowedImportFrom=<group 1 name> <group 2 name> ...

This makes it possible for separate bundles to statically import shared dependencies.

Installation

npm install --save-dev rollup-plugin-bundle-guard

Usage

rollup.config.js

const rollupPluginBundleGuard = require('rollup-plugin-bundle-guard');

export default {
  input: 'main.js',
  plugins: [
    // default config
    // rollupPluginBundleGuard(),

    // all the options
    rollupPluginBundleGuard({
      // Defaults to `false`. If enabled, all imported modules must be assigned a group.
      // Otherwise anything without a group is assigned a group named `default`
      strictMode: false,
      modules: [
        // 'react' can be imported from both the `entry` and `default` group
        { allowedImportFrom: ['entry', 'default'], module: 'react' },
        // anything that contains the string 'somegroup' will be part of the 'someGroup' group
        { group: 'someGroup', module: /somegroup/ },
      ],
      // optional. The default (below) disables checking comments for anything in 'node_modules'
      comments: {
        pathPatterns: [ /node_modules/ ],
        isWhitelist: false
      }
    })
    // ...
  ],
  // ...
});

main.js

// rollup-plugin-bundle-guard: group=entry

import 'react'; // allowed because `entry` is allowed to import `react`
import './a.js'; // allowed because `./a.js` is also in `entry`
import './b.js'; // ERROR! not allowed because `./b.js` is not in `entry`

import('./b.js'); // allowed because it's a dynamic import

a.js

// rollup-plugin-bundle-guard: group=entry

console.log('In module a.');

b.js

// rollup-plugin-bundle-guard: group=group2

import './c.js'; // ERROR! c is in `default`, not `group2`

console.log('In module b.');

c.js

// in the default group
import './d.js';

console.log('In module c.');

d.js

// in the `default` group
import 'react'; // allowed because `default` is allowed to import `react`

import './a.js'; // allowed because in non strict mode `a.js` is allowing imports from `default`

console.log('In module d.');

rollup-plugin-bundle-guard's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar greenkeeper[bot] avatar tjenkinson avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

rollup-plugin-bundle-guard's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

An in-range update of husky is breaking the build 🚨

The devDependency husky was updated from 4.0.8 to 4.0.9.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

husky is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).
  • build (12.x): There are 1 failures, 0 warnings, and 0 notices.
  • build (10.x): There are 2 failures, 0 warnings, and 0 notices.
  • build (8.x): There are 1 failures, 0 warnings, and 0 notices.

Release Notes for v4.0.9
  • Fix: read stdin from hook script (#645)
Commits

The new version differs by 2 commits ahead by 2, behind by 2.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.27.6 to 1.27.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).
  • build (12.x): There are 2 failures, 0 warnings, and 0 notices.
  • build (10.x): null
  • build (8.x): There are 1 failures, 0 warnings, and 0 notices.

Release Notes for v1.27.7

2019-12-01

Bug Fixes

  • Fix a scenario where a reassignments to computed properties were not tracked (#3267)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

return generated ast in transform, and generate sourcemap

Currently in transform() we use this.parse() which builds the ast and lets us process the comments. Rollup lets us return the ast so that it doesn't have to perform the same work again.

If we return the ast though, sourcemaps aren't generated, and sometimes there's a warning from rollup saying that the plugin is responsible for doing that.

I wonder if it's possible to still return the ast (unmodified from transform()) but have rollup generate the source map? @lukastaegert? I searched the docs but couldn't fine anything. Happy to update them.

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.