先看文件目录
.
├── entry.js // webpack 的 entry 入口文件
├── article // 文章模块
│ ├── article.js
│ └── article.html
└── product // 产品模块
├── product.js
└── product.html
Tips: 这个项目没有用到
react
或vue
等前端框架。
一共两个模块,文章 article
和 产品 product
,对应的文件是:
article.js
文章 里面有很多函数,如 aFn()
,最后都会
export default
出去。
product.js
产品 里面也有很多函数,如 pFn()
,最后都会
export default
出去。
预期访问 URL /article
执行 article.js
中的代码。 访问
/product
时执行 product.js
的代码。
entry.js
中 import p.js
和
a.js
,然后分别调用,业务代码都写在
entry.js
中。这个方法的缺点是
entry.js
会变很大,很面条。
article.html
中加载
article.js
,在 product.html
中加载
product.js
,这样最好,但是需要手动控制,而且 js
文件太多,请求次数太多,拖慢速度。
className
),然后决定执行哪些 js 代码。
想了很多方案,但没有明确答案到底那个好。其实想问的是 在使用 ES6
+
webpack
的情况下,怎么组织多页面应用(非 SPA)?
文章发布于:https://segmentfault.com/q/1010000008284105