0.0.1 • Published 4 years ago
module-tag-remove v0.0.1
About
在打包为离线包的情况下,使用@vitejs/plugin-legacy后,script标签包含了module属性和nomodule
属性,但是type = module的情况下,不能支持本地文件路径,所以直接打开会报错。
删除掉带有type=module的script标签,同时我们要去掉script的nomodule的属性,这样兼容传统浏览器的脚本在现代浏览器下也可以执行。
git clone https://github.com/posthtml/posthtml-plugin-starter.gitFeatures
Tests
The testing boilerplate includes a process() method which accepts 4 parameters:
tthe test objectnamethe file name of the fixture/expected files, excluding extensionoptionsany options to pass to the plugin when testingloga boolean that turns on logging to console
For example, imagine we're writing a test that uses /test/fixtures/skip-nodes.html:
test('It skips nodes defined in `skipNodes` option', t => {
return process(t, 'skip-nodes', {skipNodes: ['a']}, true)
})As you can see, the second parameter passed to the process() method is the fixture file name, without the .html extension.
Testing for Errors
To test errors thrown by your plugin, use the error() method:
test('Syntax error', t => {
return error('syntax-error', err => {
t.is(err.message, 'Invalid or unexpected token')
})
})Just like before, the first parameter passed to error() is the fixture file name, without the extension.
Introduction
删除vite打包后的部分script和移除nomodule属性
Input:
<script type="module">xxxxx</script>
<script nomodule id="vite-legacy-polyfill" src="./assets/polyfills-legacy.1b8c3f41.js"></script>Output:
<script id="vite-legacy-polyfill" src="./assets/polyfills-legacy.1b8c3f41.js"></script>Install
$ npm i posthtml module-tag-removeUsage
Provide clear code samples showing how to use the plugin:
import posthtml from'posthtml'
import removeScript from 'module-tag-remove'
let result = posthtml().use(plugin()).process(html, { sync: true }).html