Skip to content

tizmagik/check-filename-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Check Filename - Webpack Plugin

This Webpack plugin allows you to define a regex to test filename imports and requires against. If a regex matches, it will call the function specified to generate an error string to throw during compilation.

The error looks something like:

ERROR in ./test/test.js Module not found: Module load aborted. Only .js extensions allowed, do not use .jsx extensions. For: /Users/workspace/project/src/Component.jsx

Given the following config:

{
  regex: /\.jsx$/,
  error: pathName => `Module load aborted. Only .js extensions allowed, do not use .jsx extensions.\n\tFor: ${pathName}`
}

NOTE: error could also just be a literal string.

Install

npm install --save-dev case-sensitive-paths-webpack-plugin

Usage

import CheckFilenamePlugin from 'case-sensitive-paths-webpack-plugin';

const webpackConfig = {
    plugins: [
        new CheckFilenamePlugin({
          regex: /\.jsx$/,
          error: pathName => `Module load aborted. Only .js extensions allowed, do not use .jsx extensions.\n   For: ${pathName}`
        })
        // other plugins ...
    ]
    // other webpack config ...
}

Demo

Check the /demo directory for a working example of the plugin in action, with tests demonstrating the effect of the plugin. See /demo/README.md for more information.

Thanks & Credit

Thanks mostly to Michael Pratt who wrote case-sensitive-paths-webpack-plugin which this plugin is based mostly off of.

About

Check Filename - Webpack Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published