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

earth-scripts

v1.0.11

Published

earth for node script

Downloads

159

Readme

注:

react v15.x 使用[email protected]版本

react v16.x 使用[email protected]版本

config

  • polyfill.js

  • webpack.config.dev.js

  • webpack.config.prod.js

  • alias.js deprecated, webpackConfig.resolve.alias代替

    module.exports = {
      moduleName: '/path-to-module/xx'
    }
  • cdnPath.js deprecated, webpackConfig.output.publicPath代替

    module.exports = {
      prodJsCDN: 'http://j1.cdn.com',
      prodCssCDN: 'http://c1.cdn.com',
      prodImgCDN: 'http://img1.cdn.com',
      prodMediaCDN: 'http://media1.cdn.com'
    }
  • filenames.js deprecated, webpackConfig.output.publicPath代替

    module.exports = {
      dev: {
           js: 'static/js/[name].js',
           jsChunk: 'static/js/[name].chunk.js',
           css: '', // 在<style>中,无需配置
           img: 'static/img/[name].[hash:8].[ext]',
           media: 'static/media/[name].[hash:8].[ext]'
      },
      prod: {
          js: `static/js/[name].[chunkhash:8].js`,
          jsChunk: `static/js/[name].[chunkhash:8].chunk.js`,
          css: `static/css/[name].[chunkhash:8].css`,
          img: `static/img/[name].[chunkhash:8].[ext]`,
          media: `static/media/[name].[chunkhash:8].[ext]`
      }
    }

扩展webpack配置

在项目下建立config/webpack.config.dev.js 或者 config/webpack.config.prod.js来修改默认webpack配置

例:

webpack.config.dev.js

module.exports = {
    // todo: 支持output, externals, plugins,其他的字段都会被忽略用默认的
    output: {
        // 注: 确保 publicPath 总是以斜杠(/)开头和结尾
        publicPath: '/abc/',
        // 将原来的config/filenames.js配置到这里
        filenames: {
            js: 'static/js/[name].js',
            jsChunk: 'static/js/[name].chunk.js',
            css: '', // 在<style>中,无需配置
            img: 'static/img/[name].[hash:8].[ext]',
            media: 'static/media/[name].[hash:8].[ext]'
        }
    },
    resolve: {
        alias: {...}
    }
    externals: {
        echarts : {
            root: "echarts", // 指向全局变量
            entry: { // cdn地址
                path: 'https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.2/echarts.js',
                type: 'js',
            },
            files: ['index.html', 'test.html'] // 适用于哪个文件
        },
        jquery: {
            root: "jQuery", // 暴露给window的变量,例window.jQuery。 使用:import jQuery from 'jquery'
            entry: { // cdn地址
                path: 'http://code.jquery.com/jquery-3.3.1.min.js',
                type: 'js',
            },
            files: ['index.html'] // 适用于哪个文件
        }
    },
    cssModule: {
        exclude: ['node_modules,', 'src/static'] // 不需要css module的文件
        localIdentName: '[name]__[local]-[hash:base64:5]' // class命名方式
    },
    plugins: [
        // 可添加额外的plugins。如果添加的plugin在默认plugin里有,则会忽略
    ]
};


webpack.config.prod.js

module.exports = {
    // todo: 支持output,entry.vendor, plugins,其他的字段都会被忽略
    output: {
        // 字符串形式。
        // 资源用统一的cdn路径。
        publicPath: 'https://xxx.xxx.cdn',
        // or 对象形式。不同资源用不同的cdn
        // publicPath: {
        //    js: 'https://x1.xxx.cdn',
        //    css: 'https://x2.xxx.cdn',
        //    img: 'https://x3.xxx.cdn',
        //    media: 'https://x4.xxx.cdn'
        // },
        // 将原来的config/filenames.js配置到这里
        filenames: {
             js: 'static/js/[name].js',
             jsChunk: 'static/js/[name].chunk.js',
             css: '', // 在<style>中,无需配置
             img: 'static/img/[name].[hash:8].[ext]',
             media: 'static/media/[name].[hash:8].[ext]'
        }
    }
    entry: {
        vendor: ['immutable'],
    },
    resolve: {
        alias: {...} // 同上
    }
    externals: {
        echarts : {
            root: "echarts", // 指向全局变量
            entry: { // cdn地址
                path: 'https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.2/echarts.js',
                type: 'js',
            },
            files: ['index.html', 'test.html'] // 适用于哪个文件
        },
        jquery: {
            root: "jQuery", // 暴露给window的变量,例window.jQuery。 使用:import jQuery from 'jquery'
            entry: { // cdn地址
                path: 'http://code.jquery.com/jquery-3.3.1.min.js',
                type: 'js',
            },
            files: ['index.html'] // 适用于哪个文件
        }
    },
    cssModule: {} // 同上
    plugins: [
        // 可添加额外的plugins。如果添加的plugin在默认plugin里有,则会忽略
    ]
};
相关资料

使用.env

项目根目录下添加.env.development或.env.production文件

development环境下使用.env.development

production环境下使用.env.production

例:

dev环境下配置:
HOST=3001 // 自定义端口号
BROWSER_ROUTER=true // 是否使用BrowserRouter

prod环境下配置:
ENABLE_BUNDLE_ANALYZE=true // 在npm run build后会启用js包分析工具

mock server

npm run start在"proxy"的地址是localhost、127.0.0.1、本机ip时会启动mockserver,port为配置的端口号。 否则不会在本机启动mock server

”proxy”: “http://localhost:3001/“

自定义mock server

package.json增加字段:

"mockRoot":"server.js"

server.js为mock文件夹下自定义的mock server启动文件。如果不配置,则用默认的server

可通过 npm run start -- stopmock在dev环境下不启用mock

dev环境下browserRouter优化

page.html在url上会转化为page

例:

http://localhost:3000/index.html/[browerRouter内容]

会转化为

http://localhost:3000/index/[browerRouter内容]

需要在Router配置中加basename: publicPath(如果设置) + pageName


// publicPath: '/abc/'
// 当前pagename: 'pay.html'

<Router basename='/abc/pay'>
  ....
</Router>