Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否有考虑过添加到构建过程中的方案? #2

Open
woshiguabi opened this issue Dec 20, 2021 · 5 comments
Open

是否有考虑过添加到构建过程中的方案? #2

woshiguabi opened this issue Dec 20, 2021 · 5 comments

Comments

@woshiguabi
Copy link

例如支持webpack和rollup,通过构建生成的产物来生成loader

这样做有几个好处:
1、可以编辑html输出来将loader放在最开始加载
2、构建过程可以读取依赖包列表,转换成对应的cdn源

@woshiguabi
Copy link
Author

https://github.com/shirotech/webpack-cdn-plugin
例如这个,但是这个只提供了单个cdn的方案

@EtherDream
Copy link
Owner

有考虑过。最早的方案(Service Worker 之前)就是在构建过程中把本地 URL 替换成 CDN URL 的,后来用 Service Worker 就没考虑了,希望尽量不改已有的业务代码,除了每个页面插入一个 JS(这一步倒是可以在构建过程中插入)。

之后可以提供一些,比如公共库 JS 的搜索,根据文件 Hash 查询各个 CDN 的 URL,很多项目都可以用到。

@woshiguabi
Copy link
Author

woshiguabi commented Dec 23, 2021

有考虑过。最早的方案(Service Worker 之前)就是在构建过程中把本地 URL 替换成 CDN URL 的,后来用 Service Worker 就没考虑了,希望尽量不改已有的业务代码,除了每个页面插入一个 JS(这一步倒是可以在构建过程中插入)。

之后可以提供一些,比如公共库 JS 的搜索,根据文件 Hash 查询各个 CDN 的 URL,很多项目都可以用到。

构建过程是可以生成自动加载的Service Worker文件的,可以参考一下@vue/cli-plugin-pwa的方案

先通过workbox根据资源生成Service Worker文件
https://github.com/GoogleChrome/workbox/blob/v6/packages/workbox-webpack-plugin/src/generate-sw.js
再用webpack-html-plugin把Service Worker自动加载到<head>中去

@buptsb
Copy link

buptsb commented Dec 24, 2021

如果有 webpack 插件的确更容易上手一些,也更方便整合进现有的构建流程。

@MCSeekeri
Copy link

如果能做一个gulp插件或hexo插件就好了,根据HTML里的CDN链接自动生成SW之类...?
jsdelivr撤销国内节点之后freecdn突然就相当有吸引力了...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants