我已经配置了我的“聚合物构建”(v 2.0)来为IE 11转换ES5版本,但现在我只需要为IE 11用户提供该版本,为所有其他浏览器提供ES6版本 . 实现这一目标的最佳方法是什么?
理想情况下,我想在任何客户端页面中使用我的自定义元素只使用一次导入,并在服务器上有一些逻辑来提供适当的版本,但作为Web组件的新手,我不想自己动手解决方案(这可能是令人讨厌的)如果有一个“正确的方法”这样做(到目前为止我还没有找到它,但我会继续搜索) .
谢谢 .
您应该使用能够检测浏览器功能的Web服务器 .
Polymer Team本身已经发布了一个nodeJS库,它读取你的 polymer.json 文件并查看你的builds目录,并根据客户端浏览器支持的功能提供正确的构建 . 服务器本身也支持H2 Push,这是一个很好的功能 .
polymer.json
https://github.com/Polymer/prpl-server-node
这是我在 polymer.json 中的构建配置 . 它为每个功能生成不同的构建 . 我交叉检查,哪些版本的浏览器支持这些技术,并为每个neccecary组合添加了构建 .
"builds": [{ "name": "none", "browserCapabilities": [], "addServiceWorker": true, "bundle": true, "swPrecacheConfig": "sw-precache-config.js", "insertPrefetchLinks": true, "js": { "minify": true, "compile": true }, "css": {"minify": true}, "html": {"minify": true} }, { "name": "noes6", "browserCapabilities": ["push", "serviceworker"], "addServiceWorker": true, "addPushManifest": true, "swPrecacheConfig": "sw-precache-config.js", "insertPrefetchLinks": true, "js": { "minify": true, "compile": true }, "css": {"minify": true}, "html": {"minify": true} }, { "name": "nopush", "browserCapabilities": ["es2015", "serviceworker"], "addServiceWorker": true, "swPrecacheConfig": "sw-precache-config.js", "insertPrefetchLinks": true, "bundle": true, "js": {"minify": true}, "css": {"minify": true}, "html": {"minify": true} }, { "name": "all", "browserCapabilities": ["es2015", "push", "serviceworker"], "addServiceWorker": true, "addPushManifest": true, "swPrecacheConfig": "sw-precache-config.js", "js": {"minify": true}, "css": {"minify": true}, "html": {"minify": true} }]
还有一个简单的快速服务器,它利用prpl-server库进行差异服务(请记住,这是ES6语法):
const prpl = require('prpl-server'); const express = require('express'); const config = require('./build/polymer.json'); const app = express(); app.get('/*', prpl.makeHandler('./build/', config)); app.listen(process.env.PORT || 80);
1 回答
您应该使用能够检测浏览器功能的Web服务器 .
Polymer Team本身已经发布了一个nodeJS库,它读取你的
polymer.json
文件并查看你的builds目录,并根据客户端浏览器支持的功能提供正确的构建 . 服务器本身也支持H2 Push,这是一个很好的功能 .https://github.com/Polymer/prpl-server-node
这是我在
polymer.json
中的构建配置 . 它为每个功能生成不同的构建 . 我交叉检查,哪些版本的浏览器支持这些技术,并为每个neccecary组合添加了构建 .还有一个简单的快速服务器,它利用prpl-server库进行差异服务(请记住,这是ES6语法):