Coder Social home page Coder Social logo

pherval / webpack-config-organizer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 5.07 MB

Webpack helper to organize your configurations, separating them by concerns.

Home Page: https://www.npmjs.com/webpack-config-organizer

License: MIT License

Shell 0.65% Dockerfile 2.01% JavaScript 97.33%
webpack-configuration webpack5

webpack-config-organizer's Introduction

MIT License Publish package to npm Build & Test CodeFactor

Webpack config organizer

Webpack helper to organize your configurations separating them by concerns. This package achieves that by using two scope of files: presets and environments. Thereof you can define two types of files and both of them relies upon webpack --env CLI option. Environment configuration files help you define a config for different kinds of environments (dev, prod, debug, ci, and so on), while presets help you create predefined settings which help you to fast test a new build or just use make it cleaner.

Installation

Install using npm:

  npm install --save-dev webpack-config-organizer

Usage

First, you need to define a search path for your configs. You can use cosmiconfig to tell where to look for (package.json or .webpack-config-organizerrc.json):

// package.json
{
	"webpack-config-organizer": {
		"base": "path/to/your/env-and-presets-configs/", // relative to your project folder
		"environment": {
			"path": "/base/path/to/environment/configs/", // relative to "base"
			"prefix": "env-files-prefix"
		},
		"presets": {
			"path": "/base/path/to/presets/configs/", // relative to "base"
			"prefix": "presets-prefix"
		}
	}
}

On your webpack.config.js file use the tool to load your configurations:

const { organizer } = require("webpack-config-organizer")

module.exports = organizer({
    entry: "./src/main.js"
    output: {
        file: "[name].js"
    }
})

Using default presets

You can define default presets which are always loaded

const { organizer } = require("webpack-config-organizer")

module.exports = organizer(["typescript", "analyzer"], {
    entry: "./src/main.js"
    output: {
        file: "[name].js"
    }
})

Examples

Suppose you have the following configurations:

$ cd project-folder
$ ls build-tools/*

  build-tools/env:
  webpack.development.js
  webpack.debug.js
  webpack.ci.js

  build-tools/presets:
  webpack.typescript.js
  webpack.analyzer.js

and the given search parameters:

// package.json
{
	"webpack-config-organizer": {
		"base": "build-tools",
		"environment": {
			"path": "env",
			"prefix": "webpack."
		},
		"presets": {
			"path": "presets",
			"prefix": "webpack."
		}
	}
}

To load typescript and analyzer presets and debug environment:

$ npx webpack --env mode=debug --env.presets.typescript --env.presets.analyzer

Default presets

If you don't want to specify presets using the CLI, you can load them no matter what:

const { organizer } = require("webpack-config-organizer")

module.exports = organizer(["typescript", "analyzer"], {
    entry: "./src/main.js"
    output: {
        file: "[name].js"
    }
})

typescript and analzer presets will be always loaded:

$ npx webpack

Run Locally

Clone the project

  git clone https://github.com/pherval/webpack-config-organizer

Go to the project directory

  cd webpack-config-organizer

Install dependencies

  npm install

Build the application optionally

  npm run build

Running Tests

To run tests, run the following command

  npm t

License

MIT

webpack-config-organizer's People

Contributors

dependabot[bot] avatar noocratius avatar peterleiva avatar snyk-bot avatar

Stargazers

 avatar

Watchers

 avatar

webpack-config-organizer's Issues

ignore falsy values or empty strings

Must be ignored

module.exports = organizer([""], {
  target: "node",
  externalsPresets: { node: true },
  externals: [nodeExternals()],
});

Given:

b [Error]: Webpack build tools: Webpack configuration <path>webpack/presets/webpack. not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.