Coder Social home page Coder Social logo

sectsect / webpack-sweet-entry Goto Github PK

View Code? Open in Web Editor NEW
20.0 5.0 4.0 3.01 MB

๐Ÿ“ฆ webpack: Multiple entry points with glob pattern - Partial files named with a leading underscore - Preserve directory structure in dist directory

Home Page: https://www.npmjs.com/package/@sect/webpack-sweet-entry

License: MIT License

JavaScript 33.08% TypeScript 66.92%
webpack entrypoints es6 partial dynamic modules glob wildcards webpack5 partial-files

webpack-sweet-entry's Introduction

@sect/webpack-sweet-entry

Test codecov CodeQL npm version MIT license

Multiple entry points with glob pattern / Partial files with underscore / Preserve directory structure

Install

npm install --save-dev @sect/webpack-sweet-entry

Features

  • Multiple entry points with glob pattern.
  • Partial files (Files and Directories named with a leading underscore _ is ignored.).
  • Preserve directory structure in dist directory.

Usage Example

const webpack = require('webpack');
const path = require('path');
const { WebpackSweetEntry } = require('@sect/webpack-sweet-entry');

const sourcePath = path.join(__dirname, 'src');
const buildPath = path.join(__dirname, 'dist');

module.exports = [
  {
    entry: WebpackSweetEntry(path.resolve(sourcePath, 'assets/js/**/*.js*'), 'js', 'js'),
    output: {
      path: path.resolve(buildPath, 'assets/js'),
      filename: '[name].js',
    },
    module: {
      ...
    }
  },
  {
    entry: WebpackSweetEntry(path.resolve(sourcePath, 'assets/css/**/*.css'), 'css', 'css'),
    output: {
      path: path.resolve(buildPath, 'assets/css'),
      filename: '[name].css',
    },
    module: {
      ...
    }
  }
];

Multiple(Mixed) extentions

module.exports = [
  {
    entry: WebpackSweetEntry(path.resolve(sourcePath, 'assets/scripts/**/*.*s*'), ['ts', 'js'], 'scripts'),
    output: {
      path: path.resolve(buildPath, 'assets/js'),
      filename: '[name].js',
    },
    module: {
      ...
    }
  },
  ...
];

API

WebpackSweetEntry(path, ext, parentdir);
arg type Description Example
path string | string[] File path glob(s) path.resolve(sourcePath, 'assets/js/**/*.js*') or [path.resolve(sourcePath, 'assets/js/**/*.js*'), '!**/a.js']
ext string | string[] File extension js or ['ts', 'js']
parentdir string Parent Dirctory Name for files (The directory name where the tree starts) js

Returns object like the following.

{
  a: '/path/to/your/src/assets/js/a.js',
  b: '/path/to/your/src/assets/js/b.js',
  'dir/e': '/path/to/your/src/assets/js/dir/e.js'
}
{
  a: '/path/to/your/src/assets/css/a.css',
  b: '/path/to/your/src/assets/css/b.css',
  'dir/e': '/path/to/your/src/assets/css/dir/e.css'
}

Build Result

.
โ”œโ”€โ”€ dist
โ”‚   โ””โ”€โ”€ assets
โ”‚       โ”œโ”€โ”€ css
โ”‚       โ”‚   โ”œโ”€โ”€ a.css
โ”‚       โ”‚   โ”œโ”€โ”€ b.css
โ”‚       โ”‚   โ””โ”€โ”€ dir
โ”‚       โ”‚       โ””โ”€โ”€ e.css
โ”‚       โ””โ”€โ”€ js
โ”‚           โ”œโ”€โ”€ a.js
โ”‚           โ”œโ”€โ”€ b.js
โ”‚           โ””โ”€โ”€ dir
โ”‚               โ””โ”€โ”€ e.js
โ”œโ”€โ”€ src
โ”‚   โ””โ”€โ”€ assets
โ”‚       โ”œโ”€โ”€ css
โ”‚       โ”‚   โ”œโ”€โ”€ a.css
โ”‚       โ”‚   โ”œโ”€โ”€ b.css
โ”‚       โ”‚   โ”œโ”€โ”€ _c.css
โ”‚       โ”‚   โ”œโ”€โ”€ _d.css
โ”‚       โ”‚   โ””โ”€โ”€ dir
โ”‚       โ”‚       โ”œโ”€โ”€ e.css
โ”‚       โ”‚       โ””โ”€โ”€ _f.css
โ”‚       โ””โ”€โ”€ js
โ”‚           โ”œโ”€โ”€ a.js
โ”‚           โ”œโ”€โ”€ b.js
โ”‚           โ”œโ”€โ”€ _c.js
โ”‚           โ”œโ”€โ”€ _d.js
โ”‚           โ”œโ”€โ”€ _modules
โ”‚           โ”‚   โ”œโ”€โ”€ a.js
โ”‚           โ”‚   โ””โ”€โ”€ b.js
โ”‚           โ””โ”€โ”€ dir
โ”‚               โ”œโ”€โ”€ e.js
โ”‚               โ””โ”€โ”€ _f.js
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ postcss.config.js
โ””โ”€โ”€ webpack.config.js

Migrate from v1

$ npm uninstall webpack-sweet-entry
$ npm install --save-dev @sect/webpack-sweet-entry
- const WebpackSweetEntry = require('webpack-sweet-entry');
+ const { WebpackSweetEntry } = require('@sect/webpack-sweet-entry');

Changelog

See CHANGELOG file.

โœŒ๏ธ

A little project by @sectsect

webpack-sweet-entry's People

Contributors

dependabot[bot] avatar hmnd avatar sectsect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

webpack-sweet-entry's Issues

Support for images

Is there a way to use this plugin to process image files with different extensions?

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.