Skip to content

[chore] only import AMP validator if using AMP #3249

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

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import amp_validator from 'amphtml-validator';
import vite from 'vite';
import { rimraf } from '../../utils/filesystem.js';
import { deep_merge } from '../../utils/object.js';
Expand All @@ -27,8 +26,6 @@ export async function dev({ cwd, port, host, https, config }) {
rimraf(output);
copy_assets(output);

process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';

const [vite_config] = deep_merge(
{
server: {
Expand Down Expand Up @@ -76,7 +73,7 @@ export async function dev({ cwd, port, host, https, config }) {
hydratable: !!config.kit.hydrate
}
}),
create_plugin(config, output, cwd, config.kit.amp && (await amp_validator.getInstance()))
await create_plugin(config, output, cwd)
],
publicDir: config.kit.files.assets,
base: '/'
Expand Down
13 changes: 10 additions & 3 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ import { load_template } from '../config/index.js';
* @param {import('types/config').ValidatedConfig} config
* @param {string} output
* @param {string} cwd
* @param {import('amphtml-validator').Validator | false} amp
* @returns {import('vite').Plugin}
* @returns {Promise<import('vite').Plugin>}
*/
export function create_plugin(config, output, cwd, amp) {
export async function create_plugin(config, output, cwd) {
/** @type {import('amphtml-validator').Validator} */
let amp;

if (config.kit.amp) {
process.env.VITE_SVELTEKIT_AMP = 'true';
amp = await (await import('amphtml-validator')).getInstance();
}

return {
name: 'vite-plugin-svelte-kit',

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/test/apps/amp/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from '../../utils.js';

config.webServer && (config.webServer.timeout = 15000); // AMP validator needs a long time to get moving

// remove any projects with javaScriptEnabled
const projects = config.projects || [];
for (let i = projects.length - 1; i >= 0; i--) {
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ export const config = {
timeout: process.env.CI ? (process.platform === 'win32' ? 45000 : 30000) : 10000,
webServer: {
command: process.env.DEV ? 'npm run dev' : 'npm run build && npm run preview',
port: 3000,
timeout: 15000 // AMP validator needs a long time to get moving
port: 3000
},
workers: 8,
retries: process.env.CI ? 5 : 0,
Expand Down