框架已经集成到rubik-cli
框架主要实现前端开发中最常用的基础功能,方便扩展。 和fis推荐目录不同的是,这里没有规定具体的widget目录,只约定主要的page目录。
- 热更新
- 数据模拟
- 多页可配置(例如只够建20个页面中的某3个页面)
- standard.js语法检查
git pull
检测package.json
是否改变,改变时会重新安装包git checkout
检测package.json
是否改变,改变时会重新安装包
npx create-webpack-multi-page-app myapp
- 单元测试
├── src // 源码目录
│ │
│ ├── page // 页面目录
│ │ ├── app
│ │ │ ├── index.html
│ │ │ ├── index.js
│ │ │ ├── style.css
│ │ │ └── ...
│ │ ├── home
│ │
│ ├── assets // 公共资源目录
│ │ └── font
│ │
│ ├── model // model层
│ │
│ ├── store // 数据管理层
│ │
│ ├── anything // 根据项目特征创建
│
│
├── dist // 构建目录
│ ├── app.html
│ ├── home.html
│ ├── runtime.bundle.js
│ └── ...
│
│
├── script // npm 脚本
│ └── newpage.js
│
├── config // 配置
│ ├── build.json
│ ├── webpack.prod.js
│ ├── webpack.dev.js
│ └── webpack.common.js
│
├── mock // 数据模拟
│ └── router.js
│
├── static // 非模块目录,会直接拷贝
│
├── test // 测试
│
├── node_modules // 生态
│
$ yarn
$ yarn run start
$ open http://localhost:8081/app.html
$ yarn run build
$ yarn run new pageName
目前默认把源码根目录(src)加入到模块搜寻目录中
webpack.common.js
{
resolve: {
modules: [srcRoot, "node_modules"]
}
}
import moduleA from 'widget/a'
import moduleB from 'widget/b'
mock/router.js
下定义数据接口
module.exports = function (app) {
app.get('/data', function (req, res) {
res.json({
'data': 'hello webpack'
})
})
}
代理其他数据接口
const request = require('request')
module.exports = function (app) {
app.use('/api/', function(req, res) {
let url = `http://localhost:3000/api${req.url}`
req.pipe(request(url)).pipe(res)
})
}
请求
axios.get('/data').then(data => {
console.log(data)
})
{
"outputName": "dist",
"staticName": "static",
"templateName": "",
"publicPath": "/",
"includePage": [],
"host": "localhost",
"port": 8081,
"openStandardJs": true,
"pageTemplateWithoutHtmlLoader": false,
...
}
有时候我们想在编译阶段往页面模板传变量,html-webpack-plugin已经支持,但是由于默认所有.html
文件
都会再被html-loader
编译一次,而html-loader
是会忽略html-webpack-plugin
定义的变量的,所以增加了这个配置来
满足一些特殊需求