This JavaScript library provides gulp-like entry points in your webpack configuration.
npm install --save-dev webpack-vinyl-entry
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
.
entries: Object
- Object of webpack compatible entry points or Promises.
Returns function wrapping Promise that resolves all the promises in entries
.
globs: Array
- Array of vinyl-fs glob strings.
Globs are executed in order, so negations should follow positive globs.
Returns array of resolved paths.
scope: string
- Base directory.files: Array
- List of files or promises likeEntry.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.
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"
]
}