Skip to content

Request: rule for banning synchronous imports of arbitrary packages #1245

Open
@ryami333

Description

@ryami333

Managing bundle sizes and enforcing code-splitting in large applications can be delicate, and there is currently no mechanism which I know of to enforce that specific libraries must not be imported with ordinary import moment from 'moment'; syntax, and instead must be split like const momentPromise = import('moment').

Proposed API:

  "rules": {
    "import/no-synchronous-dependencies": ["error", {
      "packages": ['moment', 'zxcvbn']
    }]
  }

Example No. 1, errors:

import moment from 'moment'

Example No. 2, errors:

const moment = require('moment')

Example No. 3, passes

const momentLoader = import('moment')

Would there be an appetite for this? If there would be, I would consider making a PR of my own.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions