0.0.3 • Published 2 years ago

@sugarat/inlinejs-transform v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@sugarat/inlinejs-transform

HTML InlineJS Transform By SWC - 通过SWC直接处理HTML里的内联脚本

simple minify and ES Compile

Usage

npm i -g @sugarat/inlinejs-transform

or

# first
npm i @sugarat/inlinejs-transform
# second
# add ijs command into scripts

Transform

compile advanced ES syntax to specified version by SWC

ijs transform __test__/test.html

图片

ijs transform -e es5 --minify
  • -e, --ecmaVersion [ecmaVersion]: set transform jsc target version:ES5、ES5、ES2015...ES2022
  • -m, --minify: minify transform result

Minify

ijs minify __test__/test.html

图片

In PostHTML

import posthtml from 'posthtml'

import { posthtmlSWCMinify, posthtmlSWCTransform } from '@sugarat/inlinejs-transform'

const htmlCode = `<body>
  <div id="app"></div>
  <script>
    const hello = 'hello'
  </script>
  <script src="hello.js"></script>
  <script>
    const world = 'hello'
  </script>
  <script>
    console.log(hello,world);
  </script>
</body>`

// minify
const minifyResult = posthtml()
    .use(posthtmlSWCMinify())
    .process(htmlCode, { sync: true }).html

// transform
const transformResult = posthtml()
    .use(posthtmlSWCTransform('es5', true))
    .process(htmlCode, { sync: true }).html

options detail see SWC Declaration

More Info

ijs --help
ijs transform --help
ijs minify --help