Skip to content
This repository was archived by the owner on Dec 25, 2018. It is now read-only.

Specify which files should be included into 'paths' from webpack modules #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-preset-es2015": "^6.18.0",
"eslint": "^3.13.1",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-html": "^3.2.2",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-react": "^6.10.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack-contrib has it's own eslint configuration & development time dependencies controlled by https://github.com/webpack-contrib/webpack-defaults.

Please limit your pull request to the problem you are trying to solve, we will take care of code formatting & supporting tools

"eslint-plugin-standard": "^3.0.1",
"extract-text-webpack-plugin": "^3.0.2",
"git-prepush-hook": "^1.0.1",
"jest": "^18.1.0",
"npm-watch": "^0.1.8",
"purecss": "^1.0.0",
"purify-css": "^1.2.2",
"rimraf": "^2.6.1"
"rimraf": "^2.6.1",
"webpack": "^3.8.1",
"webpack-merge": "^4.1.0"
},
"pre-push": [
"build",
Expand Down
21 changes: 20 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = function PurifyPlugin(options) {
}

compiler.plugin('this-compilation', (compilation) => {
const entryPaths = parse.entryPaths(options.paths);
let entryPaths = parse.entryPaths(options.paths);


parse.flatten(entryPaths).forEach((p) => {
if (!fs.existsSync(p)) throw new Error(`Path ${p} does not exist.`);
Expand All @@ -34,6 +35,24 @@ module.exports = function PurifyPlugin(options) {
() => {};

compilation.plugin('additional-assets', (cb) => {
// Go through chunks and include them to the paths that will be parsed
if (options.modulePathsTest) {
const regexp = new RegExp(options.modulePathsTest);
const includeModules = [];

compilation.modules.forEach((mod) => {
const res = mod.resource;

if (regexp.test(res)) {
includeModules.push(res);
}
});

if (includeModules.length) {
entryPaths = entryPaths.concat(includeModules);
}
}

// Go through chunks and purify as configured
compilation.chunks.forEach(
({ name: chunkName, files, modules }) => {
Expand Down
3 changes: 3 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const schema = ({ entry } = {}) => ({
},
verbose: {
type: 'boolean'
},
modulePathsTest: {
type: 'string'
}
},
required: [
Expand Down