module-tag-remove

0.0.1 • Public • Published
PostHTML

Plugin Starter Kit

A starter project for PostHTML plugins

[![Version][npm-version-shield]][npm] [![Build][github-ci-shield]][github-ci] [![License][license-shield]][license]

About

在打包为离线包的情况下,使用@vitejs/plugin-legacy后,script标签包含了module属性和nomodule 属性,但是type = module的情况下,不能支持本地文件路径,所以直接打开会报错。

删除掉带有type=modulescript标签,同时我们要去掉scriptnomodule的属性,这样兼容传统浏览器的脚本在现代浏览器下也可以执行。

git clone https://github.com/posthtml/posthtml-plugin-starter.git

Features

  • Tests with ava
  • Linting with xo
  • Releases with np
  • Coverage with c8
  • CI with GitHub Actions

Tests

The testing boilerplate includes a process() method which accepts 4 parameters:

  • t the test object
  • name the file name of the fixture/expected files, excluding extension
  • options any options to pass to the plugin when testing
  • log a 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-remove

Usage

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

Package Sidebar

Install

npm i module-tag-remove

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

11 kB

Total Files

13

Last publish

Collaborators

  • huangchucai