Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtallent committed Jan 14, 2024
1 parent 11a7271 commit 70f812a
Show file tree
Hide file tree
Showing 6 changed files with 2,770 additions and 5,662 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
| 2023-02-11 | 0.13.3 | Bump build dependencies, update README |
| 2023-04-01 | 0.13.5 | Allow reporting of compressed bundle size (#70, #71, thanks @mojoaxel!) |
| | | Fix where polfill not removed when minify disabled (#72) |
| 2024-01-14 | 1.0.0 | Vite 5, Node 18 is now required. This is a breaking change! |
| | | Fixed relative URLs (#75, #86, thanks @atomiechen!) |
| | | Switched from jest to vitest |
| | | Fix plugin type |
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Web applications running from a local file have some browser security limitation
- SPA routing requires using hash-based routes -- the web history API doesn't work for local files, and a web browser will not allow you to navigate between local HTML files.
- Any sourcemaps you generate will be useless, since this plugin bundles the compiled files after sourcemaps are generated. Turning off esbuild's minification in your vite config will at least ensure the code is legible when debugging.

Last but not least, this is a **single file** plugin. As in, it creates **one HTML file**. Hence the name. So, this **will not work** with multi-page apps. Please see issue #51 for details.
**This is a _single file_ plugin. As in, it creates _one HTML file_ and _no other files_. Hence the name. So, this _will not work_ with multi-page apps. Please see issue #51 for details. Issues opened requesting multiple entry points will be closed as `wontfix`.**

## Installation

Expand Down
17 changes: 9 additions & 8 deletions __tests__/replaceScript.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const src = require("../dist/cjs/index.js")
import { describe, test, expect } from "vitest"
import { replaceScript } from "../dist/esm/index.js"

describe("Replace Script", () => {
test("It should inline external scripts and preserve other script attributes", () => {
const outputMod = "<script module>\n\n</script>"
expect(src.replaceScript(`<script module src="./foo.js"></script>`, "foo.js", "")).toEqual(outputMod)
expect(src.replaceScript(`<script src="./foo.js" module></script>`, "foo.js", "")).toEqual(outputMod)
expect(replaceScript(`<script module src="./foo.js"></script>`, "foo.js", "")).toEqual(outputMod)
expect(replaceScript(`<script src="./foo.js" module></script>`, "foo.js", "")).toEqual(outputMod)
const outAsync = "<script async module>\n\n</script>"
expect(src.replaceScript(`<script async src="./foo.js" module></script>`, "foo.js", "")).toEqual(outAsync)
expect(src.replaceScript(`<script src="./foo.js" async module></script>`, "foo.js", "")).toEqual(outAsync)
expect(replaceScript(`<script async src="./foo.js" module></script>`, "foo.js", "")).toEqual(outAsync)
expect(replaceScript(`<script src="./foo.js" async module></script>`, "foo.js", "")).toEqual(outAsync)
const outCrossOrigin = `<script async type="module" crossorigin>\n\n</script>`
expect(src.replaceScript(`<script async type="module" crossorigin src="/assets/foo.js"></script>`, "assets/foo.js", "")).toEqual(outCrossOrigin)
expect(replaceScript(`<script async type="module" crossorigin src="/assets/foo.js"></script>`, "assets/foo.js", "")).toEqual(outCrossOrigin)
const outPolyfill = `<script type="module">\n`
// Removing polyfill without minification
expect(src.replaceScript(`<script type="module" crossorigin>\n(function polyfill() {stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill)
expect(replaceScript(`<script type="module" crossorigin>\n(function polyfill() {stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill)
// Removing polyfill with minification
expect(src.replaceScript(`<script type="module" crossorigin>\n(function(){stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill)
expect(replaceScript(`<script type="module" crossorigin>\n(function(){stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill)
})
})
Loading

0 comments on commit 70f812a

Please sign in to comment.