rewrite-imports

WebJar for rewrite-imports

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

rewrite-imports
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

rewrite-imports
WebJar for rewrite-imports
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/lukeed/rewrite-imports

Download rewrite-imports

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/rewrite-imports/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>rewrite-imports</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/rewrite-imports/
implementation 'org.webjars.npm:rewrite-imports:1.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/rewrite-imports/
implementation ("org.webjars.npm:rewrite-imports:1.2.0")
'org.webjars.npm:rewrite-imports:jar:1.2.0'
<dependency org="org.webjars.npm" name="rewrite-imports" rev="1.2.0">
  <artifact name="rewrite-imports" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='rewrite-imports', version='1.2.0')
)
libraryDependencies += "org.webjars.npm" % "rewrite-imports" % "1.2.0"
[org.webjars.npm/rewrite-imports "1.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

rewrite-imports Build Status

Transforms various import statements into require() calls, using regular expressions.

Looking for something more backwards compatible?
Check out v1.4.0 which does not rely on destructured assignment!

Caveats

This module returns a string and does not provide a runtime nor does it evaluate the output.

💡 For this behavior, use rewrite-module or check out @taskr/esnext for an example.

The output requires a JavaScript runtime that supports require calls and destructuring assignments with Objects.

  • At least Node 6.x is required

  • Or, for browsers:

    • A require shim is always needed – see fn
    • Ensure your target browsers support destructuring – see chart

If you have false positives, you may want to use an AST to find actual import statements before transformation.

Check out an example implementation.

Install

$ npm install --save rewrite-imports

Usage

const rImports = require('rewrite-imports');

rImports(`import foo from '../bar'`);
//=> const foo = require('../bar');

rImports(`import { foo } from 'bar'`);
//=> const { foo } = require('bar');

rImports(`import * as path from 'path';`);
//=> const path = require('path');

rImports(`import { foo as bar, baz as bat, lol } from 'quz';`);
//=> const { foo:bar, baz:bat, lol } = require('quz');

rImports(`import foobar, { foo as FOO, bar } from 'foobar';`);
//=> const foobar = require('foobar');
//=> const { foo:FOO, bar } = foobar;

API

rImports(input, fn)

input

Type: String

The import statement(s) or the code containing import statement(s).

See MDN for valid import statement syntax.

fn

Type: String
Default: 'require'

The require-like function name to use. Defaults to require but you may choose to pass the name of a custom shim function; for example, __webpack_require__ may work for webpack in the browser.

License

MIT © Luke Edwards

Versions

Version
1.2.0