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

@lorndev/agnostic-bundler

v0.2.2

Published

A simple bundler for CMS or backend HTML frameworks to compile TS, JS, SCSS and CSS files.

Downloads

40

Readme

Agnostic Bundler

A simple bundler for CMS and other websites that can't be built with new tools and need separate CSS/JS assets.

Overview

Features

| Feature | Informations | | ------------------------- | ------------------------------------------------------------------------------- | | Esbuild | Base functionnalities (compile, import/export behavior, create bundle etc...) | | Typescript | TypeScript compiler, use babel after compilation (JS and TS consistency) | | Sass | Transform your SCSS stylesheets to standard CSS | | PostCSS | Concact and organize CSS, mapped with .browserslinkrc like Babel | | Autoprefixer | Autoprefix your CSS for many browsers | | SVG Inline | Minify SVG outputed files | | ESLint | JavaScript/TS linter, make your project sane and robust |

Requirements

| Dependencies | Version | | ------------------------- | ------------------------- | | NPM | v6.13 | | NodeJS | v14.14 |

Files structure

This package

node_modules/@lorndev/agnostic-bundler
├── .browserslistrc           # Example file for Browserlistrc
├── .eslintrc                 # Example file for Eslint
├── tsconfig.json             # Example TypeScript configuration
└── config.default.json       # Example config.json

# (package.json, .editorconfig...)

Sources folder (<project_root>/.bundler for example)

Your src folder need to be a copy of src_default to start your project.

src
├── config.json               # Override config.default.json, same function
├── distribution              # Contain project distribution (Not exported at build can only serve dependencies like sass mixins etc)
└── public                    # Exported dir into project public root (for example public dir is <project_root>/web for Drupal 9)

# (package.json, .editorconfig, .git, node_modules ...)

Getting Started

Starting your project from skratch easyly !

Installation

First step install or create your project root dependencies (Drupal, Wordpress, Symfony, Sylius as you want..). Follow next steps or just copy this repository as a base : Bundler src boilerplate

  • Create a folder which contain your sources (.bundler for example)
  • Run in console npm install @lorndev/agnostic-bundler
  • Run npm install
  • Copying config.default.json (remove .default) .eslintrc tsconfig.json and .browserlistrc at root of .bundler
  • Setup your configuration
  • Create run scripts in your package.json as below :
{
// code ...
  "scripts": {
    "build": "agnostic-bundler --production --lint",
    "dev": "agnostic-bundler --watch --sourcemap --lint"
  }
// code ...
}

Configuration

Your main configuration is in your sources folder, config.json, this file override config.default.json.

Take that into consideration :

Base configuration is an example for Drupal website which has theme named vanksen. For drupal public folder is <project_root>/web, so this is your mapped dir with <project_root>/.bundler/public folder and it's mapped with / website route. Remember, your configuration paths is relative from npm script running folder in this case <project_root>/.bundler.

Common configuration

Agnostic bundler package provides a configuration file which is loaded first to configure the bundler. In most of the cases, this is the only configuration file you need to edit. See comments below for more informations :

{
  "src": "public",                                                    // The files to compiles
  "dist": "build",                                                    // The compiled file directory
  "vendors": ["distribution"],                                        // Every Sass or JS dependencies that you don't need to parse as entries
  "lintedExtensions": [".js", ".ts", ".jsx", ".tsx"],                 // Extension to check with Eslint
  "compileExtensions": [".js", ".ts", ".scss"],                       // Extension to compile and watch
  "exclude": "/(node_modules|bower_components)/",                     // Excluded regex from src
  "browserSync": {                                                    // Browsersync configuration
    "host": "localhost",
    "proxy": "example.com",
    "port": 4200,
    "ui": { "port": 4201 },
    "open": false,
    "socket": {
      "domain": "localhost:4200"
    },
    "injectChanges": true,
    "watchEvents": ["change"],
    "files": [
      "build/**/*.js",
      "build/**/*.css"
    ],
    "ignore": [
      "build/some-pattern"
    ],
    "watchOptions": {
      "usePolling": true
    }
  },
  "sass": {                                                           // Sass options (override)
    "loadPaths": ["distribution/sass", "node_modules"]
  },
  "esbuild": {                                                        // Esbuild options (override)
    "target": "es6"
  },
  "copy": {                                                           // Copy options
    "ignore": [".ts",".js",".scss",".gitkeep"]
  }
}

CLI Options

  • --lint : Enable linter (based on your .eslint config file at root)
  • --production : Minify files and remove sourcemap from dist
  • --sourcemap : Generate sourcemaps for JS/CSS (TS, Sass etc.)
  • --watch : Hotreload and browsersync

Usages

First step, run npm install

Production and development

Easy to use :

  • npx run agnostic-bundler --lint --watch --sourcemap : Development
  • npx run agnostic-bundler --lint --production Production

Entries & bundle

Use bundle functionnality

All files not prefixed by underscore is a bundle, agnostic-bundler integrate static imports and others depencencies in the generated bundle. So, use underscore _ to specify if your file is a dependency.

For example :

public/_dependency.ts

export class Example {

  private message: string;

  public constructor () {
    this.message = 'Hello World !';
  }

  public displayMessage() {
    return console.log(this.message);
  }
}

public/mybundle.ts

import { Example } from './_dependency';

new Example().displayMessage();

In this example, agnostic-bundler generate a file ( mybundle.js the bundle) which contain example class and code of _dependency.ts.

Use dynamic imports

The dynamic import works different, the imported class isn't integrated in the bundled file but a chunks with specific id is generated. So, when the dynamic import function is called, the chunk file is automatically added to JS file in browser.

For example, to dynamically import bootstrap from node_modules :

public/mybundle.ts

setTimeout(() => {
  import('bootstrap').then(bootstrap => console.log(bootstrap));
},3000)