All Projects → samrith-s → Parcel Plugin Structurize

samrith-s / Parcel Plugin Structurize

Licence: mit
A plugin to customize the output (dist) directory structure during production.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Parcel Plugin Structurize

dumber
A dumb JavasScript bundler for Single Page Application, dumber than you and me.
Stars: ✭ 21 (-27.59%)
Mutual labels:  bundler
Eustia
Tool for generating utility libraries
Stars: ✭ 276 (+851.72%)
Mutual labels:  bundler
Mam mol
$mol - fastest reactive micro-modular compact flexible lazy ui web framework.
Stars: ✭ 385 (+1227.59%)
Mutual labels:  bundler
website
Documentation for the SWC project.
Stars: ✭ 53 (+82.76%)
Mutual labels:  bundler
Webpack-4-boilerplate
🚀 Webpack 4 with ES6+ and SASS,LESS/STYLUS support + dev-server and livereload
Stars: ✭ 55 (+89.66%)
Mutual labels:  bundler
Svelvet
🧵 An experimental svelte compiler & watcher that works with snowpack
Stars: ✭ 310 (+968.97%)
Mutual labels:  bundler
The-HTML-and-CSS-Workshop
A New, Interactive Approach to Learning HTML and CSS
Stars: ✭ 65 (+124.14%)
Mutual labels:  bundler
Sheetify
✨ Modular CSS bundler for browserify
Stars: ✭ 443 (+1427.59%)
Mutual labels:  bundler
circleci-ruby-orbs
CircleCI orb for ruby
Stars: ✭ 16 (-44.83%)
Mutual labels:  bundler
Trunk
Build, bundle & ship your Rust WASM application to the web.
Stars: ✭ 378 (+1203.45%)
Mutual labels:  bundler
ng2-fused
FuseBox plugins and utilities for building Angular2 applications.
Stars: ✭ 13 (-55.17%)
Mutual labels:  bundler
rolldown
Modern bundler built on Rollup with couple more features, such as multiple entry points, presets, better configuration experience and more.
Stars: ✭ 17 (-41.38%)
Mutual labels:  bundler
Wp Webpack Script
💥🔥📦👩‍💻 An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.
Stars: ✭ 314 (+982.76%)
Mutual labels:  bundler
jasper
🧳 Single-binary packaging for Ruby applications that supports native and Wasm targets
Stars: ✭ 29 (+0%)
Mutual labels:  bundler
Metro
🚇 The JavaScript bundler for React Native.
Stars: ✭ 4,308 (+14755.17%)
Mutual labels:  bundler
bundler-comparison
Comparison of web resource bundlers. 📦
Stars: ✭ 21 (-27.59%)
Mutual labels:  bundler
Notebook As Pdf
Save Jupyter Notebooks as PDF
Stars: ✭ 290 (+900%)
Mutual labels:  bundler
Packem
📦⚡ A precompiled JavaScript module bundler
Stars: ✭ 586 (+1920.69%)
Mutual labels:  bundler
Fuse Box
A blazing fast js bundler/loader with a comprehensive API 🔥
Stars: ✭ 4,055 (+13882.76%)
Mutual labels:  bundler
Pundle
👾 peaceful bundles - js bundler, built from the ground up for speed and extensibility
Stars: ✭ 354 (+1120.69%)
Mutual labels:  bundler

parcel-plugin-structurize

npm (tag) checks

A Parcel plugin that lets you customize your output (dist) directory folder structure.

If you ❤️ this plugin and want to support, you can buy me a coffee!

Buy Me A Coffee

🗃 Table of Contents

🤔 Why?

When building for production, Parcel outputs the build in a flat structure. In some cases, we might need a particular structure for the built output.

This plugin lets you organize every file output by Parcel by matching and moving assets into your desired structure. It also updates all references in every file to ensure that the output is ready for consumption with your custom structure.

Advantages of using the plugin:

  • Supports excellent and fine-grained configuration for all use cases out of the box using glob pattern matching
  • Super fast and rapid restructuring means you do not need to worry about a massive overload in build times.
  • Respects publicUrl passed to Parcel bundler while restructuring the folder.
  • Respects the outDir passed to Parcel bundler and only restructures files within.
  • Sensible defaults to get you up and running quickly.

🔌 Installation

Installation is straight forward using NPM or Yarn:

# Using NPM
npm install --save-dev parcel-plugin-structurize

# Using Yarn
yarn add -D parcel-plugin-structurize

🚛 Migrating from 1.x

Migrating from v1 to v2 of the plugin is super simple.

In your project, first upgrade the plugin:

yarn upgrade [email protected]

Then upgrade the configuration in package.json:

# package.json file
{
    "parcel-plugin-structurize": {
-        "scripts": {
-            "match": "*.{js,js.map}",
-            "folder": "js"
-        },
-        "styles": {
-            "match": "*.{css,css.map}",
-            "folder": "css"
-        },
-        "assets": {
-            "match": "*.{png,svg,jpg,jpg2,jpeg,gif,bmp,webm}",
-            "folder": "assets"
-        }
+        "rules": [
+            {
+                "match": "*.js",
+                "folder": "js",
+            },
+            {
+                "match": "*.css",
+                "folder": "css",
+            },
+            {
+                "match": "*.{png,svg,jpg,jpg2,jpeg,gif,bmp,webm}",
+                "folder": "assets",
+            },
+        ],
    }
}

🏃‍♀️ Usage

There are two ways to configure the plugin:

  • Adding the parcel-plugin-structurize key to package.json.
// package.json
{
    "parcel-plugin-structurize": {
        "rules": [
            {
                "match": "*.js",
                "folder": "scripts"
            },
            {
                "match": "*.{jpg,png,gif,svg}",
                "folder": "images"
            }
        ]
    }
}
  • Via a parcel-plugin-structurize.json file in your project root (right next to your package.json).
// parcel-plugin-structurize.json
{
    "rules": [
        {
            "match": "*.js",
            "folder": "scripts"
        },
        {
            "match": "*.{jpg,png,gif,svg}",
            "folder": "images"
        }
    ]
}

Note: This plugin runs ONLY in parcel build or when NODE_ENV=production, since the use-case of running it in watch, serve or NODE_ENV=development is not compelling enough.


🛠 Configuration

The plugin allows for fine-grained configuration options to ensure proper customization of the output directory.

Options

The configuration includes the following options:

  • rules

    Structurizer

    An array of objects which are called Structurizers.

  • verbose

    boolean

    Whether to enable verbose logging or not.

  • displayAssetsMap

    boolean

    Whether to display the generated assets map or not. This only comes into effect if verbose is true.

Disable plugin

You can disable the plugin by two means:

  • Set rules attribute in your config to false.
  • Set environment variable PARCEL_PLUGIN_STRUCTURIZE to false. Ex:
PARCEL_PLUGIN_STRUCTURIZE=false parcel build src/index.html

🧱 Structurizer

Structurizer is a rule that contains match patterns and the target.

type Config = {
    match: string;
    folder: string;
    flatten?: boolean;
};
  • match

    string

    A glob pattern to match file names and group them to a folder.

  • folder

    string

    The folder to place the files in. Can contain nested folders (ex: scripts/vendors, images/vectors/user/avatar)

  • flatten

    boolean

    For nested files, whether to flatten them to the output folder or not.

You can provide as many Structurizers in your configuration file. The plugin ships with sensible defaults.

// default config
{
    "verbose": false,
    "rules": [
        {
            "match": "*.js",
            "folder": "js",
            "flatten": false
        },
        {
            "match": "*.css",
            "folder": "css",
            "flatten": false
        },
        {
            "match": "*.{jpg,jpeg,jpeg2,png,gif,svg,bmp,webp}",
            "folder": "assets",
            "flatten": false
        }
    ]
}

❗️ Gotchas

  1. The order of the Structurizers matter if you want to target a glob and a file ending with the same extension. To better illustrate this, let's consider the following files in your output directory:

    • index.html
    • contact.html
    • about.html

    If you want to move all HTML files into a folder called app, except the index.html then you need to keep in mind the order of the Structurizers.

# The following will produce the desired results
+ Correct
[
    {
        "match": "index.html",
        "folder": "."
    },
    {
        "match": "*.html",
        "folder": "app"
    }
]

# And the following will result in your `index.html` to be placed inside the `app` directory as well
- Incorrect
[
    {
        "match": "*.html",
        "folder": "app"
    },
    {
        "match": "index.html",
        "folder": "."
    }
]
  1. You should NOT add any structurizer rules for .map files as the plugin automatically resolves and restructures the sourcemap files to reside in the same directory as its parent. This can cause unintended side-effects.

🐠 Contributing

To get the project up and running, clone it and then run the following command:

yarn bootstrap

It will install all packages, link dependencies and set everything up. To start the dev server:

yarn dev

To build the bundle, simply run:

yarn build

Bundling

Bundles watch for changes to the plugin and rebuild with Parcel bundler, causing the plugin to trigger. Once you have the plugin running in dev mode, you can run the following command for the bundles:

(cd __tests__/bundle && yarn dev)

Testing

To test you can run:

yarn test:watch

Bugs and issues

Please report any bugs here. For any questions feel free to create an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].