Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Nettsentrisk committed Aug 20, 2018
0 parents commit 91978a1
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# globbed-webpack-entries-plugin

[![license][license]][license-url]

Provides a way to glob for entry files in Webpack `watch` and `non-watch` modes.

## Usage

```js
import GlobbedEntriesPlugin from 'globbed-webpack-entries-plugin';

// In your Webpack config:
{

entry: GlobbedEntriesPlugin.entries({
global : ['./Scripts/index.js', './Styles/main.scss']
}
)

plugins: [
new GlobbedEntriesPlugin(),
]
}
```
59 changes: 59 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const glob = require('glob');
const globBase = require('glob-base');

let directories = [];

class GlobEntries {
static entries(entryObject) {
return function () {
const entries = {};

for (let bundle in entryObject) {

if (entryObject.hasOwnProperty(bundle) && Array.isArray(entryObject[bundle])) {
let files = [];

entryObject[bundle].forEach(globString => {
let globDirectory = globBase(globString).base;

if (directories.indexOf(globDirectory) < 0) {
directories.push(globDirectory);
}

files = files.concat(glob.sync(globString));
});

if (files.length) {
entries[bundle] = files;
}
}
}

return entries;
}
}

/**
* Install Plugin
* @param {Object} compiler
*/
apply(compiler) {
if (compiler.hooks) {
compiler.hooks.afterCompile.tapAsync(this.constructor.name, this.afterCompile.bind(this));
}
}

/**
* After compiling, give webpack the globbed files
* @param {Object} compilation
* @param {Function} callback
*/
afterCompile(compilation, callback) {
for (const directory of directories) {
compilation.contextDependencies.add(directory);
}
callback();
}
}

module.exports = GlobEntries;
115 changes: 115 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"author": "George Gooding <[email protected]>",
"dependencies": {
"glob": "^7.1.2",
"glob-base": "^0.3.0"
},
"description": "File type agnostic globbed webpack entries with watching.",
"license": "MIT",
"main": "index.js",
"name": "globbed-webpack-entries-plugin",
"peerDependencies": {
"webpack": "4.x"
},
"private": false,
"repository": "https://github.com/Nettsentrisk/globbed-webpack-entries-plugin",
"version": "1.0.0"
}

0 comments on commit 91978a1

Please sign in to comment.