├── .babelrc ├── .flowconfig ├── .gitignore ├── .npmignore ├── Makefile ├── README.md ├── example ├── src │ ├── index.js │ └── other.js └── webpack.config.js ├── package.json └── src └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["prometheusresearch"] 3 | } 4 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/node_modules/esformatter/.* 3 | .*/node_modules/fbjs/.*.flow 4 | .*/node_modules/fbjs/.*.js 5 | .*/node_modules/.store/fbjs@.*/.*.flow 6 | .*/node_modules/.store/gh-pages@.*/.* 7 | .*/node_modules/.store/browserify-zlib@.*/_/package.json 8 | .*/test/.* 9 | 10 | [include] 11 | 12 | [libs] 13 | declarations/ 14 | 15 | [options] 16 | esproposal.class_static_fields=enable 17 | esproposal.class_instance_fields=enable 18 | unsafe.enable_getters_and_setters=true 19 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | output/ 3 | lib/ 4 | examples/webpack/bundle 5 | site/bundle 6 | npm-debug.log 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | npm-debug.log 3 | .nyc_output/ 4 | coverage/ 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DELETE_ON_ERROR: 2 | 3 | BIN = ./node_modules/.bin 4 | TESTS = $(shell find src -path '*/__tests__/*-test.js') 5 | SRC = $(filter-out $(TESTS) $(FIXTURES), $(shell find src -name '*.js')) 6 | LIB = $(SRC:src/%=lib/%) 7 | MOCHA_OPTS = -R dot --require babel-core/register 8 | 9 | build:: 10 | @$(MAKE) -j 8 $(LIB) 11 | 12 | doctoc: 13 | @$(BIN)/doctoc --title '**Table of Contents**' ./README.md 14 | 15 | lint:: 16 | @$(BIN)/eslint src 17 | 18 | check:: 19 | @$(BIN)/flow --show-all-errors src 20 | 21 | test:: 22 | @$(BIN)/mocha $(MOCHA_OPTS) $(TESTS) 23 | 24 | ci-unit:: 25 | @$(BIN)/mocha $(MOCHA_OPTS) --watch $(TESTS) 26 | 27 | sloc:: 28 | @$(BIN)/sloc -e __tests__ src 29 | 30 | version-major version-minor version-patch:: lint 31 | @npm version $(@:version-%=%) 32 | 33 | publish:: build 34 | @git push --tags origin HEAD:master 35 | @npm publish 36 | 37 | clean:: 38 | @rm -rf lib 39 | 40 | lib/%.js: src/%.js 41 | @echo "Building $<" 42 | @mkdir -p $(@D) 43 | @$(BIN)/babel $(BABEL_OPTIONS) -o $@ $< 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # prefetch-context-webpack-plugin 2 | 3 | Webpack plugin which prefetches context (all files within the directory tested 4 | by a regular expression). 5 | 6 | The usecase I had in mind is to use it in combination with `eslint-loader` to 7 | lint not only the files which are in dep tree but every file in a source 8 | directory. 9 | 10 | Example configuration w/ `eslint-loader`: 11 | 12 | ``` 13 | import PrefetchContext from 'prefetch-context-webpack-plugin' 14 | 15 | module.exports = { 16 | 17 | ... 18 | 19 | plugins: [ 20 | new PrefetchContext({ 21 | context: './src', 22 | loader: 'eslint-loader', 23 | }) 24 | ] 25 | } 26 | ``` 27 | 28 | Now every file within the `./src` directory will be linted. 29 | -------------------------------------------------------------------------------- /example/src/index.js: -------------------------------------------------------------------------------- 1 | x + 1; 2 | -------------------------------------------------------------------------------- /example/src/other.js: -------------------------------------------------------------------------------- 1 | console.log('some ok'); 2 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var PrefetchContext = require('../').default; 3 | 4 | module.exports = { 5 | context: path.join(__dirname, 'src'), 6 | output: { 7 | path: 'build', 8 | filename: 'bundle.js', 9 | }, 10 | plugins: [ 11 | new PrefetchContext({loader: 'eslint-loader'}), 12 | ], 13 | eslint: { 14 | baseConfig: 'prometheusresearch', 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prefetch-context-webpack-plugin", 3 | "version": "0.1.0", 4 | "description": "Webpack plugin for prefetching all files within the context", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "make test" 8 | }, 9 | "eslintConfig": { 10 | "extends": "prometheusresearch" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/andreypopp/prefetch-context-webpack-plugin.git" 15 | }, 16 | "keywords": [ 17 | "webpack", 18 | "webpack-plugin" 19 | ], 20 | "author": "Andrey Popp <8mayday@gmail.com>", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/andreypopp/prefetch-context-webpack-plugin/issues" 24 | }, 25 | "homepage": "https://github.com/andreypopp/prefetch-context-webpack-plugin#readme", 26 | "devDependencies": { 27 | "babel-cli": "^6.9.0", 28 | "babel-core": "^6.9.1", 29 | "babel-preset-prometheusresearch": "^0.1.0", 30 | "eslint": "^2.11.1", 31 | "eslint-config-prometheusresearch": "^0.2.0", 32 | "flow-bin": "^0.26.0", 33 | "webpack": "^1.13.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @copyright 2016-present, Andrey Popp <8mayday@gmail.com> 3 | */ 4 | 5 | import ContextDependency from 'webpack/lib/dependencies/ContextDependency'; 6 | 7 | export default class PrefetchAllPlugin { 8 | 9 | constructor(config) { 10 | this.config = config; 11 | } 12 | 13 | apply(compiler) { 14 | let lastHash = null; 15 | let context = this.config.context ? 16 | this.config.context : 17 | compiler.context; 18 | 19 | compiler.plugin('compilation', (compilation, params) => { 20 | compilation.dependencyFactories.set( 21 | ContextDependency, 22 | params.contextModuleFactory 23 | ); 24 | }); 25 | 26 | compiler.plugin('make', (compilation, cb) => { 27 | let request = this.config.loader ? 28 | `!!${this.config.loader}!${context}` : 29 | `!!${context}`; 30 | let test = this.config.test ? 31 | this.config.test : 32 | /\.js$/; 33 | let dep = new ContextDependency(request, true, test); 34 | compilation.prefetch(context, dep, err => { 35 | if (err) { 36 | cb(err); 37 | } else { 38 | cb(null); 39 | } 40 | }); 41 | }); 42 | 43 | compiler.plugin('done', (stats) => { 44 | // We do this because webpack by default suppresses output if compilation 45 | // output wasn't changed. 46 | if (stats.hash === lastHash) { 47 | process.stdout.write(stats.toString({}) + '\n'); 48 | } 49 | lastHash = stats.hash; 50 | }); 51 | } 52 | } 53 | --------------------------------------------------------------------------------