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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-scripts-webpack-chain

v0.0.1

Published

fork create-react-app/[email protected]

Downloads

17

Readme

react-scripts

fork create-react-app/packages/[email protected]

https://github.com/facebook/create-react-app

特性

  1. 常用打包配置
  2. 支持自定义常用配置
  3. 原有eslint配置调整为 eslint-config-lfe
  4. 原有sass改为less写样式文件

常用打包配置

  1. 支持config包多环境加载配置
  2. 打包输出路径为target/{projectName}/

支持自定义配置

需要创建app.config.js文件在项目根目录

配置项:

| 配置项 | 说明 | 默认值 | | ------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | define | 注入对象到webpack.DefinePlugin插件中 | {} | | appBuild | 打包输出路径 | target/${packageJson.name} | | appPublic | 静态文件路径 | static | | appHtml | HtmlWebpackPlugin插件template路径 | static/index.html | | appIndexJs | webpack打包入口文件 | src/index | | servedPath | production时输出静态文件域名 | '' | | publicUrl | 打包时输出静态文件路径,production时优先使用servedPath, 只publicUrl也可以 | '' | | eslintLoader | 启用eslintLoading | false | | ignoreTSError | ForkTsCheckerWebpackPlugin插件中ignoreDiagnostics配置 | [] | | webpackDevProxy | 暂时没用 | - | | modifyVars | less配置中options.modifyVars | {} | | webpack | 使用webpackChain覆盖配置格式为:function(webpackConfig, isBuild, options){webpackConfig.entry('app').xxxx}webpackConfig: webpackChain对象isBuild:是否执行的是npm run buildoptions: 当前配置 | null | | proxy | WebpackDevServer配置中proxy配置 | null | | enableReactHotLoader | 是否启动react-hot-loader babel | react-hot-loader babel配置是否启用, 包括 @hot-loader配置 默认: false, 使用说明: https://github.com/gaearon/react-hot-loader | | enablePostcssPXToRem | 是否启用PostcssPXToRem插件 | 默认: false | | postcssPXToRemArgs | postcssPXToRem插件参数 | 默认: rootValue: 100, propWhiteList: [] | | enablePostcssPXToViewport | 是否启用postcssPXToViewport插件 | 默认: false | | postcssPXToViewportArgs | postcssPXToViewport插件参数 | 默认: 375配置, 详见源代码 |

webpackBundleAnalyzerPlugin使用

EN_ANALYZER=true && npm run build

webpack自定义配置实例

项目中目前自定义的配置, 使用到的地方可以在此共享展示, 后续可以把通用的配置集成到脚手架中

demo

    if (!isBuild) {
      // 增加react-hot-loader
      webpackConfig
        .entry('app')
        .prepend(require.resolve('react-hot-loader/patch'))
        .end()
        .resolve.alias.set('react-dom', '@hot-loader/react-dom');
    } else {
      // 输出静态文件去掉hash指纹
      webpackConfig.output
        .filename('static/js/[name].js')
        .chunkFilename('static/js/[name].chunk.js');
      webpackConfig.plugin('miniCssExtractPlugin').tap(() => [
        {
          filename: 'static/css/[name].css',
          chunkFilename: 'static/css/[name].chunk.css',
        },
      ]);
    }
		// 增加antd icon 按需加载
    webpackConfig.resolve.alias.set(
      '@ant-design/icons/lib/dist$',
      path.resolve(process.cwd(), './src/common/icons.ts')
    );
		// 增加analyzer插件
    if (process.env.EN_ANALYZER === 'true') {
      webpackConfig
        .plugin('bundleAnalyzer')
        .use(BundleAnalyzerPlugin.BundleAnalyzerPlugin);
    }

demo

    if (!isBuild) {
      // 增加react-hot-loader
      webpackConfig
        .entry('app')
        .prepend(require.resolve('react-hot-loader/patch'))
        .end()
        .resolve.alias.set('react-dom', '@hot-loader/react-dom');
    }

    // 增加postcss to vw插件
    const lessUses = webpackConfig.module.rule('compile').oneOf('less').uses;
    lessUses.values().forEach((use) => {
      use
        .tap((args) => {
          if (args && args.ident === 'postcss') {
            return Object.assign(args, {
              plugins: [
                require('postcss-px-to-viewport')({
                  viewportWidth: 375, // 设计稿宽度
                  viewportHeight: 667, // 设计稿高度,可以不指定
                  unitPrecision: 3, // px to vw无法整除时,保留几位小数
                  viewportUnit: 'vw', // 转换成vw单位
                  selectorBlackList: ['.ignore', '.hairlines'], // 不转换的类名
                  minPixelValue: 1, // 小于1px不转换
                  mediaQuery: false, // 允许媒体查询中转换
                }),
              ],
            });
          }
          return args;
        })
        .end();
    });