npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aternus/babel-plugin-include

v2.0.1

Published

Adds the ability to use `include` as part of the JavaScript syntax. Includes external JavaScript code inline.

Downloads

53

Readme

@aternus/babel-plugin-include

Adds support for the include() function to the Babel compiler.

Why use this plugin?

A simple way to organize and reuse code.

The goal of this plugin is to allow a "native" way of including JavaScript code inline - at compilation time.

Installation

npm install -D @aternus/babel-plugin-include @babel/core @babel/cli

.babelrc.json / babel.config.json (Recommended)

{
  "plugins": ["@aternus/babel-plugin-include"]
}

Usage

The include() function takes an argument, a file path, e.g. file.js.

Code

main.js

include('welcome.js');
include('stateManager.js');

welcome.js

console.log('Welcome code');

stateManager.js

console.log('State manager code');

Result after compilation with Babel

console.log('Welcome code');
console.log('State manager code');

FAQ

  • The include() function takes a single string as an argument. Following arguments are ignored.
  • The included file must be a valid JavaScript file. If there are errors the compiler will throw an error.
  • The default encoding is assumed to be utf8.
  • You can use relative and absolute filenames, and change the root directory in plugin options.

Programmatic Invocation

Node API

const transformedCode = require('@babel/core').transform(code, {
  plugins: ['@aternus/babel-plugin-include'],
});

CLI

npx babel --plugins @aternus/babel-plugin-include main.js

Integrations

IDEs / TypeScript

The plugin ships with TypeScript types which the IDEs and TypeScript can use to understand the new include syntax capability without you having to take any action.

⚠ Keep in mind that you'll still need to use Babel as the transpiler (this is a babel plugin after all 😅)

ESLint

The plugin ships with an ESLint config you can extend to avoid getting errors about include being undefined.

In your .eslintrc.js:

module.exports = {
  extends: [
    // ...
    './node_modules/@aternus/babel-plugin-include/eslint',
  ],
  // ...
};

./node_modules is required to ensure that ESLint won't add "eslint-config" to the package name, resulting in a wrong path.

Options

You can provide an options object to modify the default behavior of the plugin.

{
  plugins: [['@aternus/babel-plugin-include', options]];
}

The following options are available:

| Option Name | Type | Default | Notes | | ----------- | ---------------- | ------------------- | ------------------------------------------------------------------------- | | root | string | cwd() of the file | The root directory from which all files will be included. | | encoding | BufferEncoding | utf-8 | The encoding option specifies which encoding to use when including files. |

Credits

vihanb for the original package (no longer maintained).

License

Released under the MIT License - see LICENSE.md for details.