npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lines-webpack-plugin

v1.0.0

Published

限制文件行数的webpack插件

Readme


简介

前端项目开发中,文件行数过多,影响代码的可读性。本插件可以自定义指定目录下每个文件的行数限制,超过限制则警告或者报错。可以用于提醒开发者合理规划文件大小。

安装使用

1. 安装包使用方式

# npm
npm install lines-webpack-plugin -D
或
npm install lines-webpack-plugin -D --registry=https://registry.npmmirror.com

# yarn
yarn add lines-webpack-plugin -D

2.如何使用

  • webpack.config.js 中引入插件
const path = require("path");
const {LinesWebpackPlugin} = require("lines-webpack-plugin");
plugins: [
    new LinesWebpackPlugin(
        //可以配置多个检测规则
        [
            {
                directory: path.resolve(__dirname, './demo'), // 需要检测的目录
                allowedExtensions: ['.ts', '.js'], // 需要检测的文件后缀,默认['ts','tsx','js']
                maxLines: 12, // 报错最大行数,默认600
                warningLines: 8, // 警告最大行数,默认500
                excludedPaths: [path.resolve(__dirname, './demo/list')], // 需要排除文件夹或文件,默认[]
                errorStatus: false // 如果超过报错限制行数构建过程是否终止,默认true
            }
        ]
    )
]
  • 使用webpack-chain时
const path = require("path");
const {LinesWebpackPlugin} = require("lines-webpack-plugin");
config.plugin('LinesWebpackPlugin').use(LinesWebpackPlugin,
        [
            [{
                directory: path.resolve(__dirname, './demo'), // 需要检测的目录
                allowedExtensions: ['.ts', '.js'], // 需要检测的文件后缀,默认['ts','tsx','js']
                maxLines: 12, // 报错最大行数,默认600
                warningLines: 8, // 警告最大行数,默认500
                excludedPaths: [path.resolve(__dirname, './demo/list')], // 需要排除文件夹或文件,默认[]
                errorStatus: false // 如果超过报错限制行数构建过程是否终止,默认true
            }]
        ]
    );
return config;

3. 参数说明

  • 可以定义多个规则,所以参数传入的是一个数组,数组中为一个或多个对象,每个对象参数说明如下:

| 参数 | 说明 | 默认值 | |:------------------|:---------------------------------------------------|:----------------------------| | directory | 需要检测项目中的哪个文件夹,使用path.resolve(__dirname, './') | 必填 | | allowedExtensions | 需要检测的文件的后缀名 | 选填,默认值['ts','tsx','js'] | | maxLines | 当检测的文件超过报错最大行数时,会打印出超出的文件路径及当前文件行数 | 选填,默认值600 | | warningLines | 当检测的文件超过警告最大行数时,会打印出超出的文件路径及当前文件行数 | 选填,默认值500 | | excludedPaths | 需要排除哪些文件或者文件夹 | 选填,默认值[] | | errorStatus | 如果超过报错限制行数构建过程是否终止 | 选填,默认值true |

4. 测试例子

# npm
cd lines-webpack-plugin

npm install 
或
npm install --registry=https://registry.npmmirror.com

npm run example

5. 提示内容

Warning: File E:\other\ceshi\plugins\lines-webpack-plugin\example\demo\warning.js has more than warningLines(8) lines:9
Error: File E:\other\ceshi\plugins\lines-webpack-plugin\example\demo\test.js has more than maxLines(12) lines:18
超出警告或者报错限制行数,会在控制台打印如上内容
第一条为警告提示内容,颜色为洋红色
第二条为报错提示内容,颜色为红色