0.0.2 • Published 3 years ago

@pacy/routes-webpack-plugin v0.0.2

Weekly downloads
1
License
-
Repository
github
Last release
3 years ago

@pacy/routes-webpack-plugin

NPM version NPM Downloads Prettier Conventional Commits

routes webpack plugin

Installation

npm install @pacy/routes-webpack-plugin
# or use yarn
yarn add @pacy/routes-webpack-plugin

Usage

  • webpack config
import * as nps from 'path'
import RoutesWebpackPlugin from '@pacy/routes-webpack-plugin'

module.exports = {
  plugins: [
    new RoutesWebpackPlugin({
      // 用来占位的文件
      inputFilename: '/path/to/routes-placeholder',
      // 被解析生成目录结构树的文件目录
      dirPatterns: ['/path/to/src/pages'],
      // 被观察的文件目录
      watchPatterns: ['/path/to/src/pages'],
      // 写成什么样子
      toSourceString: async (data) => {
        return `
module.exports = [
  ${data.map(
    (filename) => `{
  name: ${JSON.stringify(nps.relative(nps.dirname('/path/to/routes-placeholder'), filename))},
  source: () => import(${JSON.stringify(filename)}),
}`
  )}
];
`
      }
    })
  ]
}

Contributing

  • Fork it!
  • Create your new branch:
    git checkout -b feature-new or git checkout -b fix-which-bug
  • Start your magic work now
  • Make sure npm test passes
  • Commit your changes:
    git commit -am 'feat: some description (close #123)' or git commit -am 'fix: some description (fix #123)'
  • Push to the branch: git push
  • Submit a pull request :)

Authors

This library is written and maintained by 余聪.

License

MIT - 余聪