0.0.2 • Published 4 years ago
@pacy/routes-webpack-plugin v0.0.2
@pacy/routes-webpack-plugin
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
orgit 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)'
orgit 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 - 余聪
0.0.2
4 years ago