Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: srcset handling in html #6419

Merged
merged 13 commits into from May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/playground/env/__tests__/env.spec.ts
Expand Up @@ -3,7 +3,7 @@ import { isBuild } from 'testUtils'
const mode = isBuild ? `production` : `development`

test('base', async () => {
expect(await page.textContent('.base')).toBe('/')
expect(await page.textContent('.base')).toBe('/env/')
})

test('mode', async () => {
Expand Down Expand Up @@ -46,9 +46,15 @@ test('env object', async () => {
VITE_EFFECTIVE_MODE_FILE_NAME: `.env.${mode}`,
CUSTOM_PREFIX_ENV_VARIABLE: '1',
VITE_CUSTOM_ENV_VARIABLE: '1',
BASE_URL: '/',
BASE_URL: '/env/',
MODE: mode,
DEV: !isBuild,
PROD: isBuild
})
})

if (!isBuild) {
test('relative url import script return import.meta.url', async () => {
expect(await page.textContent('.url')).toMatch('/env/index.js')
})
}
2 changes: 2 additions & 0 deletions packages/playground/env/index.html
Expand Up @@ -14,6 +14,7 @@ <h1>Environment Variables</h1>
<p>import.meta.env.VITE_INLINE: <code class="inline"></code></p>
<p>process.env.NODE_ENV: <code class="node-env"></code></p>
<p>import.meta.env: <span class="pre env-object"></span></p>
<p>import.meta.url: <span class="pre url"></span></p>

<script type="module">
text('.base', import.meta.env.BASE_URL)
Expand All @@ -31,6 +32,7 @@ <h1>Environment Variables</h1>
document.querySelector(el).textContent = text
}
</script>
<script type="module" src="./index.js"></script>

<style>
.pre {
Expand Down
5 changes: 5 additions & 0 deletions packages/playground/env/index.js
@@ -0,0 +1,5 @@
text('.url', import.meta.url)

function text(el, text) {
document.querySelector(el).textContent = text
}
6 changes: 5 additions & 1 deletion packages/playground/env/vite.config.js
@@ -1,5 +1,9 @@
const { defineConfig } = require('vite')

module.exports = defineConfig({
envPrefix: ['VITE_', 'CUSTOM_PREFIX_']
base: '/env/',
envPrefix: ['VITE_', 'CUSTOM_PREFIX_'],
build: {
outDir: 'dist/env'
}
})
5 changes: 1 addition & 4 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Expand Up @@ -79,10 +79,7 @@ const processNodeUrl = (
s.overwrite(
node.value!.loc.start.offset,
node.value!.loc.end.offset,
`"${path.posix.join(
path.posix.relative(originalUrl, '/'),
url.slice(1)
)}"`
poyoho marked this conversation as resolved.
Show resolved Hide resolved
`"${url}"`
)
}
}
Expand Down