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

vp-ssr

v1.0.0

Published

react 服务端渲染 node公共方法 webpack配置

Downloads

40

Readme

@vp/ssr

@vp/ssr node react babel

安装

npm i @vp/ssr --registry=http://npm.vpgame.cn

1.目录介绍

packages(组件源码) 
lib (组件编译之后代码)

2.开发编译

实时编译 npm run watch
npm link
项目中npm link @vp/ssr

3.发布组件

npm version patch
npm run build
npm publish

4.组件规范

目前的规范如下

  • packages 目录下index.ts 暴露组件
    • 每个组件对应一个文件夹原则上文件夹名字小写
    • 每个组件内部有一个index.ts 暴露组件以及引入对应的样式文件

5.使用

corsMiddleware

import { corsMiddleware } from '@vp/ssr'
app.use(corsMiddleware({}))

apiMiddleware

import { apiMiddleware } from '@vp/ssr'
app.use(apiMiddleware({
  prefix,
  fetch,
  serviceList,
  routePath
}))

serviceList

const serviceList = [{
  key: 'yii',
  url: process.env.YII_URL
}, {
  key: 'api',
  url: process.env.SERVICE_URL,
}]

renderMiddleware

import { renderMiddleware } from '@vp/ssr'
app.use(renderMiddleware(renderConfig))

renderConfig

import App from '../../client/container/App'
import getStore from '../../client/redux/store'
import { setLanguage } from '../../client/action/language'
import { fetchUserInfo } from '../../client/container/App/action'
import { fetchNavInfo } from '../../client/container/App/navAction'
import { fetchNotice } from '../../client/container/App/noticeAction'
import routes, { ACTIVE_PATH } from '../../controllers'
import locales from '../locales'

const config = {
  App,
  getStore,
  setLanguage,
  routes,
  fetchList: [{
    action: fetchUserInfo,
    params: {
      activePath: ACTIVE_PATH
    }
  }, {
    action: fetchNavInfo,
  }, {
    action: fetchNotice,
  }],
  locales,
  beforeLoad: (ctx, route) => {
    console.log('beforeLoad')
  },
  beforeRender: (ctx, route) => {
    console.log('beforeRender')
  }
}

export default config

Logger

import { Logger } from '@vp/ssr'
global.logger = Logger({
  logPath: process.env.LOG_PATH,
  isDev: __DEV__
})

setSeo

import { setSeo } from '@vp/ssr'
setSeo({
  fetch,
  routePath: INDEX_PATH,
})

fetch

import { fetch as utilFetch } from 'vp-utils'
import { isClient } from './util'
import serviceList from '../server/config/serviceList'
import versions from '../server/config/versions'

const fetch = params => utilFetch({
  serviceList,
  versions,
  indexPath: process.env.ROUTE_PATH,
  type: isClient ? 'client' : 'server',
  logger: global.logger,
  serverHost: process.env.SERVER_API_HOST,
  serverPort: process.env.SERVER_API_PORT,
  isDev: __DEV__
})(params)

export default fetch

server.js

const { webpackDevServer } = require('@vp/ssr')
const webpackConfig = require('./webpack.config')

webpackDevServer(webpackConfig)

paths.js

const { paths } = require('@vp/ssr')

module.exports = paths

isomorphic-config.js

const { webpackIsomorphicConfig } = require('@vp/ssr')

module.exports = webpackIsomorphicConfig

webpack.config.js PC项目可直接使用 webpack config,可以添加自定义配置

const { webpackConfig } = require('@vp/ssr')

module.exports = webpackConfig

项目根目录创建customConfig.js可进行webpack部分内容进行配置

module.exports = {

  /** less options */
  lessDefaultOptions: {

    modifyVars: {
      hd: '3px',
      'brand-primary': '#3C3C3C',
    },
    javascriptEnabled: true
  },

  /** 开启 BundleAnalyzerPlugin 开关 默认关闭 */
  enableDll: false,

  /**  HtmlWebpackPlugin 配置 */
  HtmlWebpackConfig: {},

  /**  sass-resources-loader 配置 */
  sassResourcesLoaderOptions: {}

  /** loader rules */
  loaderRules: [],

  /** 是否引入core-js 默认true
   * @babel/preset-env 配置 useBuiltIns: "usage" 时设置为false
   * @babel/preset-env 配置 useBuiltIns: "entry" 时设置为true
  */
  useCoreJs: true
}

DonePlugin (webpack构建完成执行文件操作插件 原createVersion已内置 production生成version.txt) 默认webpack已添加该插件

构建完成需要对文件进行操作可使用此插件

  const { DonePlugin } = require('@vp/ssr')

  //构建完成对文件进行操作
  new DonePlugin({
    fileHandler: [{
      /** 文件路劲 */
      filePath: string
      /**
       * 处理文件
       * @param content string 文件文本内容
       * @return string 返回修改后的文件内容
       */
      handler: (content: string) => string
    }]
  })

注意

  • autoprefixer 以及 postcss-pxtorem 已从webpack配置去除 如需配置postcss-loader 如需使用如下:

    项目根目录创建postcss.config.js

    module.exports = {
      plugins: {
        'autoprefixer': {},
        'postcss-pxtorem': {
          rootValue: 124.2,
          propWhiteList: []
        }
      }
    }