dokmic / webpack-vinyl-entry

The pretty webpack entry points

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webpack Vinyl Entry

NPM Build Status Code Coverage

This JavaScript library provides gulp-like entry points in your webpack configuration.

Install

npm install --save-dev webpack-vinyl-entry

Usage

In your webpack.config.js:

const Entry = require('webpack-vinyl-entry');

module.exports = {
  entry: new Entry({
    bundle1: Entry.src([
      '**/*.js',
      '!**/*.test.js',
      '!webpack.config.js'
    ]),
    bundle2: [
      'path/to/file1.js',
      'path/to/file2.js',
    ],
    pages: Entry.multi('src/pages', [
      'src/common.js',
      Entry.src([
        'src/components/**/index.js',
        'src/pages/**/index.js',
      ]),
    ]),
  }),

  // ...
};

This statement generates function wrapper over Promise that returns webpack compatible entry points. You can use whatever is accepted by webpack in the object values and besides that you can easly generate an entry from gulpjs/vinyl-fs globs by using Entry.src.

API

Entry(entries)

  • entries: Object - Object of webpack compatible entry points or Promises.

Returns function wrapping Promise that resolves all the promises in entries.

Entry.src(globs)

Globs are executed in order, so negations should follow positive globs.

Returns array of resolved paths.

Entry.multi(scope, files)

  • scope: string - Base directory.
  • files: Array - List of files or promises like Entry.src.

Generates multi-page entries from the base directory. All the files that don't belong to the base directory will be added at the beginning of every entry.

Example

Let's say we have the following file structure:

- src/
    common.js
  - pages/
    - page1/
       index.js
       component.js
    - page2/
       index.js

And the following piece of code in webpack.config.js:

pages: Entry.multi('src/pages', [
  'src/common.js',
  Entry.src([
    'src/pages/**/*.js',
  ]),
]),

That will generate us two entry points:

{
  "page1": [
    "src/common.js",
    "src/page1/index.js",
    "src/page1/component.js"
  ],
  "page2": [
    "src/common.js",
    "src/page2/index.js"
  ]
}

Links

About

The pretty webpack entry points

License:MIT License


Languages

Language:JavaScript 100.0%