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

beauty-webpack

v1.2.9

Published

webpack

Downloads

34

Readme

Beauty-webpack

NPM GitHub package.json version

Motive

快速搭建前端项目,减少webpack配置学习成本

Install

npm install beauty-webpack --save-dev

Usage

命令

//package.json
{
  "script": {
      //开发
      "start": "beauty start",
      //打包
      "build": "beauty build",
      //分析
      "analyze": "beauty analyze"
  }
}

Spa项目

目录结构

.
+-- src
|   +-- ...
|   +-- index.(js|jsx)

入口文件

//src/index.js
import React from 'react'
import ReactDOM from 'react-dom'

const Home=()=><div>Home</div>

ReactDOM.render(<Home/>, document.querySelector('#root'))

Mpa项目

目录结构

.
+-- src
|   +-- ...
|   +-- activity
|       +-- index.(js|jsx)
|   +-- home
|       +-- index.(js|jsx)

入口文件

//src/(folder)/index.js
import React from 'react'
import ReactDOM from 'react-dom'

const Home=()=><div>Home</div>

ReactDOM.render(<Home/>, document.querySelector('#root'))

配置文件

允许自定义添加配置文件修改webpack配置 需要在根目录添加.beautyrc.js文件

属性

属性|说明|备注 ---|---|--- entry|入口配置(只限Spa项目)|参考webpack entry output|输出配置| 参考webpack output publicPath|文件输出目录|参考webpack publicPath isExtractCss|是否提取公共样式| alias|别名|默认@为src文件夹 splitChunks|分包策略|参考webpack splitChunks chunks|js分包模块|配合entry define|定义项目全局变量|参考webpack define devServer|开发服务器配置|参考webpack devServer title|输出页面的title| port|开发服务器端口号|默认值:3000 open|开发服务器编译完成是否立即打开页面 babelPlugins|babel插件引入|babelPlugins: [["import", {"libraryName": "antd","libraryDirectory": "es","style": true // `style: true` 会加载 less 文件}]] isCssModule|是否开启css module| 默认值:true isRem|是否启用rem|默认值:true rootFontSize|根元素字体大小|默认值:75

配置文件例子

//.beautyrc.js
const path = require('path')
const PREFIX = process.env.PREFIX
const env = process.env.NODE_ENV

module.exports = {
    entry: {
        track: path.resolve(__dirname, './src/utils/track'),
        beauty: ['@babel/polyfill', path.resolve(__dirname, './src/index')]
    },
    chunks: ['vendor', 'beauty', 'track'],
    isExtractCss: env !== 'development',
    define: {
        "process.env.BASE_NAME": JSON.stringify(PREFIX || '')
    },
    splitChunks: {
        maxAsyncRequests: Infinity,
        maxInitialRequests: Infinity,
        minSize: 10000,
        cacheGroups: {
            vendor: {
                name: 'vendor',
                chunks: 'all',
                test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
            },
            clipboard: {
                name: 'clipboard',
                chunks: 'all',
                test: /[\\/]node_modules[\\/](clipboard)[\\/]/,
            }
        }
    }
}

模版文件

默认有模板文件,需要自定义可以在src目录下添加document.ejs 配置参数参考html-webpack-plugin

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0"/>
    <script src="//web-cdn.meilly.cn/stash/flexible.js"></script>
    <title><%= htmlWebpackPlugin.options.title %></title>
    <link rel="icon" href="/favicon.png" type="image/x-icon"/>
</head>
<body>
<noscript>Sorry, we need js to run correctly!</noscript>
<div id="root">
</div>
<% htmlWebpackPlugin.files.js.forEach(function(js) { %>
    <script src="<%= js %>"></script>
<% }) %>
<% if(webpackConfig.mode === 'production') { %>
    <script defer
            src="https://jic.talkingdata.com/app/h5/v1?appid=2F65664B662A4C80A0F941774CFD28FB&vn=mellyv1.0&vc=2.7.1"></script>
<% } %>
</body>
</html>