/lighthouse-ci-test

Create an automated process for running Lighthouse CI in a local env as well as in the preview, dev, and production env of a Next.js application.

Primary LanguageHTML

Getting Started

First, run the development server:

npm run dev

Open http://localhost:3000 with your browser to see the result.

Run Lighthouse Audit:

yarn run test:lighthouse 

Configurations:

  • Edit lighthouserc.js file
// For running on local env 

module.exports = {
	ci: {
		collect: {
			url: ['http://localhost:3000']
			startServerCommand: 'yarn run dev',
		},
		assert: {
		  preset: 'lighthouse:recommended'
		},
		upload: {
			target: 'temporary-public-storage',
		},
	},
};
// For running on prod env

module.exports = {
	ci: {
		collect: {
			url: [`https://${process.env.PREVIEW_URL}`],
			startServerCommand: process.env.NODE_ENV === 'production' ? undefined : 'npm run start',
		},
		assert: {
			// preset: 'lighthouse:recommended',
			preset: 'lighthouse:no-pwa',
		},
		upload: {
			target: 'temporary-public-storage',
		},
	},
};

Learn More

To learn more about Next.js, take a look at the following resources: