Skip to content

Commit

Permalink
feat: 0.4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxch committed Apr 10, 2023
1 parent 128cc31 commit eb4c15f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 158 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## Changelog

### 0.4.9

_2023-04-11_
#### Fix

- fix html template src parse ([#21](https://github.com/chenxch/vite-plugin-dynamic-base/issues/21))

### 0.4.8

_2022-01-15_
_2023-01-15_
#### Fix

- fix legacy assets path ([#19](https://github.com/chenxch/vite-plugin-dynamic-base/issues/19) by [@jgsrty](https://github.com/jgsrty))
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## Changelog

### 0.4.9

_2023-04-11_
#### Fix

- 修复html模版src解析 ([#21](https://github.com/chenxch/vite-plugin-dynamic-base/issues/21))

### 0.4.8

_2022-01-15_
_2023-01-15_
#### Fix

- 修复 legacy 资源路径 ([#19](https://github.com/chenxch/vite-plugin-dynamic-base/issues/19) by [@jgsrty](https://github.com/jgsrty))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ npm i vite-plugin-dynamic-base -D

## Changelog

### 0.4.8
### 0.4.9

_2022-01-15_
_2023-04-11_
#### Fix

- fix legacy assets path ([#19](https://github.com/chenxch/vite-plugin-dynamic-base/issues/19) by [@jgsrty](https://github.com/jgsrty))
- fix html template src parse ([#21](https://github.com/chenxch/vite-plugin-dynamic-base/issues/21))


[Changelogs](./CHANGELOG.md)
Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ npm i vite-plugin-dynamic-base -D

## 变更日志

### 0.4.8
### 0.4.9

_2022-01-15_
_2023-04-11_
#### Fix

- 修复 legacy 资源路径 ([#19](https://github.com/chenxch/vite-plugin-dynamic-base/issues/19) by [@jgsrty](https://github.com/jgsrty))
- 修复html模版src解析 ([#21](https://github.com/chenxch/vite-plugin-dynamic-base/issues/21))


[变更日志](./CHANGELOG.zh-CN.md)
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
window.__dynamic_base__ = 'http:https://localhost:8090'
window.__dynamic_base__ = 'http:https://localhost:4173'
</script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion examples/src/publicPath.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
window.__dynamic_base__ = 'http:https://localhost:8090'
window.__dynamic_base__ = 'http:https://localhost:4173'
181 changes: 34 additions & 147 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function replaceQuotes(mark: string, placeholder: string, code: string) {
const doublePlaceholder = `${placeholder}+"/`
const templateMark = `\`${mark}`;
const templatePlaceholder = `\`\$\{${placeholder}\}/`;
return replace(doubleMark, doublePlaceholder, replace(singleMark, singlePlaceholder, replace(templateMark, templatePlaceholder, code)));
const srcMark = `src="${mark}`
const srcPlaceholder = `src="'+${placeholder}+'/`
return replace(doubleMark, doublePlaceholder, replace(srcMark, srcPlaceholder, replace(singleMark, singlePlaceholder, replace(templateMark, templatePlaceholder, code))));
}

// replace asset url
Expand Down
25 changes: 25 additions & 0 deletions tests/transform.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, test } from 'vitest'
import { transformChunk } from '../src/core/transform'

describe('transform', () => {
const options = { publicPath: 'window.__dynamic_base__', assetsDir: 'assets', base: '/__dynamic_base__/', legacy: false, transformIndexHtml: false }

test('transformChunk-es', () => {
const code = `i = d('<div class="container-pc"><div class="bg"><img src="/__dynamic_base__/assets/asd.10e5228f.png" alt="" class="ignore-logo"><div class="ignore-title"></div><div class="ignore-sub-title"></div></div></div>;',1)`
const result = transformChunk('es', code, options)
expect(result).toEqual(`i = d('<div class="container-pc"><div class="bg"><img src="'+window.__dynamic_base__+'/assets/asd.10e5228f.png" alt="" class="ignore-logo"><div class="ignore-title"></div><div class="ignore-sub-title"></div></div></div>;',1)`)
})

test('transformChunk-es-doublequote', () => {
const code = `var ji=n("d", "/__dynamic_base__/assets/logo.03d6d6da.png"),`
const result = transformChunk('es', code, options)
expect(result).toEqual(`var ji=n("d", window.__dynamic_base__+"/assets/logo.03d6d6da.png"),`)
})


test('transformChunk-system', () => {
const code = `return c.innerHTML="a[data-v-b4cdb4a4]{color:#42b983}label[data-v-b4cdb4a4]{margin:0 .5em;font-weight:700}code[data-v-b4cdb4a4]{background-color:#eee;padding:2px 4px;border-radius:4px;color:#304455}.base{width:100px;height:100px;background-image:url(/__dynamic_base__/assets/logo.03d6d6da.png)}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px}\n",`
const result = transformChunk('system', code, options)
expect(result).toEqual(`return c.innerHTML="a[data-v-b4cdb4a4]{color:#42b983}label[data-v-b4cdb4a4]{margin:0 .5em;font-weight:700}code[data-v-b4cdb4a4]{background-color:#eee;padding:2px 4px;border-radius:4px;color:#304455}.base{width:100px;height:100px;background-image:url("+window.__dynamic_base__+"/assets/logo.03d6d6da.png)}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px}\n",`)
})
})

0 comments on commit eb4c15f

Please sign in to comment.