Is it possible to use subresource integrity with ES6 module imports?

后端 未结 4 1829
广开言路
广开言路 2020-12-06 00:37

Given code like this:

import { el, mount } from \'https://unpkg.com/redom@3.2.1/dist/redom.es.js\';

is there some way to enable subresource

4条回答
  •  清歌不尽
    2020-12-06 01:12

    You can use RequireJS, and transpile your code to AMD or UMD to achieve this. RequireJS has a hook onNodeCreated, which gives you access to the script tag before it is added to document. You can add the sri attribute onto the script tag:

    onNodeCreated: function(node, config, module, path) { node.setAttribute('integrity', integrityForModule); node.setAttribute('crossorigin', 'anonymous'); }

    credit: https://stackoverflow.com/a/37065379

    I use Webpack (with a target of UMD) and RequireJS. With the relevant modules put in the external section of the webpack configuration file, so the modules are not compiled into the transpiled code.

提交回复
热议问题