Giter Site home page Giter Site logo

shaoml / sveltekit-crxjs-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 118 KB

A boilerplate of chrome extension built on sveltekit prerender pages.

License: MIT License

HTML 6.07% Svelte 5.50% JavaScript 21.38% TypeScript 67.06%
chrome-extension crx svelte sveltekit vite-plugin

sveltekit-crxjs-boilerplate's Introduction

sveltekit-crxjs-boilerplate

构建工具

依赖项目

源码结构

src
├── routes
│   ├── popup/+page.svelte
│   └── +layout.ts
├── scripts
│   ├── background.ts
│   └── content.ts
├── app.html
└── manifest.ts
static
└── icons
    ├── 16.png
    ├── 48.png
    └── 128.png

How to use

从本项目开始

  • 克隆项目到本地,安装依赖 npm i ,并构建项目 npm run build
  • 用 chrome 打开 chrome://extensions/,开启开发者模式,点击加载已解压的扩展程序,选择到项目目录下的build目录。
  • 在 chrome 的扩展工具栏中固定图标,点击图标,显示弹窗并开始计时。

从新项目开始

  • sveltekit 构建骨架项目。
npm create svelte@latest app-name
# select: Skeleton project
# select: Yes, using TypeScript syntax
  • 设置预渲染模式。
// src/routes/+layout.ts
export const prerender = true;
  • 复制清单文件 src/manifest.ts 及其关联的图标、脚本、页面等。
  • 复制dependencies目录到新项目根目录下,并安装依赖 npm i
  • 配置构建选项:
// svelte.config.js
import adapter from '@sveltejs/adapter-static'; // Required
import { vitePreprocess } from '@sveltejs/kit/vite';

const config = {
	preprocess: vitePreprocess(),

	kit: {
		appDir: 'app', // Required
		adapter: adapter({ strict: true }), // Required
		csp: { directives: { 'script-src': ['self'] } }, // optional
	},
};

export default config;
// vite.config.ts
import { crx } from '@crxjs/vite-plugin'; // Required
import { sveltekit } from '@sveltejs/kit/vite';
import { resolve } from 'path';
import { mergeConfig, type UserConfig } from 'vite';
import manifest from './src/manifest'; // Required

const config: UserConfig = {
	plugins: [
		sveltekit(),
		crx({ manifest }), // Required
		{
			name: 'mergeConfig',
			apply: 'build',
			enforce: 'post',
			config(config) {
				return mergeConfig(config, {
					publicDir: 'static', // Required
				});
			},
		},
	],
	build: { assetsInlineLimit: 0 }, // optional
	resolve: {
		alias: {
			'~': resolve(__dirname, 'src'), // optional
		},
	},
};

export default config;
  • 构建项目 npm run build,并在 chrome 中调试。方法同从本项目开始

代码风格

  • 格式化
// .vscode/settings.json
{
	"editor.formatOnSave": true,
	"editor.defaultFormatter": "esbenp.prettier-vscode",
	"editor.codeActionsOnSave": {
		"source.organizeImports": true,
		"source.fixAll.eslint": true,
		"source.fixAll.stylelint": true
	},
	"eslint.validate": ["svelte"],
	"stylelint.validate": ["svelte"],
	"[svelte]": {
		"editor.formatOnSave": true,
		"editor.defaultFormatter": "svelte.svelte-vscode"
	}
}
// .prettierrc
// 删除
{
	"plugins": ["prettier-plugin-svelte"],
	"pluginSearchDirs": ["."],
	"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
npm i -D stylelint stylelint-config-standard stylelint-config-prettier stylelint-config-recess-order
npm i -D postcss-html stylelint-config-html
// .stylelintrc
{
	"extends": [
		"stylelint-config-html/svelte",
		"stylelint-config-standard",
		"stylelint-config-prettier",
		"stylelint-config-recess-order"
	]
}

sveltekit-crxjs-boilerplate's People

Contributors

shaoml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ryonzhang

sveltekit-crxjs-boilerplate's Issues

How to use in dev mode?

When running npm dev and then loading the extension from the dist folder doesn't work - the svelte files are not being complied. Any solution for that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.