Skip to content

Commit

Permalink
feat: 支持开发模式全自动热重载
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 13, 2023
1 parent 1be577b commit bc7b5cb
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 711 deletions.
4 changes: 2 additions & 2 deletions apps/publisher-app/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Svelte + TS + Vite
# publisher-app

This template should help get you started developing with Svelte and TypeScript in Vite.
app module for publisher

## Recommended IDE Setup

Expand Down
11 changes: 5 additions & 6 deletions apps/publisher-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
"version": "1.1.3",
"type": "module",
"scripts": {
"dev": "vite",
"serve": "vite",
"dev": "vite build --watch",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"syncVersion": "echo 'syncVersion in app'"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.0.3",
"@terwer/eslint-config-custom": "latest",
"@terwer/eslint-config-custom": "^1.2.0",
"@terwer/vite-config-custom": "^0.4.0",
"@tsconfig/svelte": "^4.0.1",
"svelte": "^3.57.0",
"svelte-check": "^2.10.3",
"tslib": "^2.5.0",
"typescript": "^5.0.2",
"vite": "^4.3.2"
"svelte-check": "^2.10.3"
}
}
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
"plugins/*"
],
"scripts": {
"serve": "turbo run serve",
"dev": "turbo run dev",
"build": "turbo run build",
"localBuild": "turbo run localBuild",
"staticBuild": "turbo run staticBuild",
"nodeBuild": "turbo run nodeBuild",
"dockerBuild": "turbo run dockerBuild",
"vercelBuild": "turbo run vercelBuild",
"siyuanBuild": "turbo run siyuanBuild",
"syncVersion": "turbo run syncVersion",
"package": "echo 'package in root'",
"test": "turbo run test",
"start": "turbo run start",
"doc": "turbo run doc",
"lint": "turbo run lint",
"graph": " turbo run build --graph=dependency-graph.png",
"prepare": "is-ci || husky install",
Expand Down
29 changes: 25 additions & 4 deletions plugins/publisher-main/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
module.exports = {
root: true,
extends: ["./node_modules/@terwer/eslint-config-custom/index.cjs"],
ignorePatterns: ["node_modules/"],
}
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"turbo",
"prettier",
],

parser: "@typescript-eslint/parser",

plugins: ["@typescript-eslint", "prettier"],

rules: {
// Note: you must disable the base rule as it can report incorrect errors
semi: "off",
quotes: "off",
"no-undef": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"turbo/no-undeclared-env-vars": "off",
"prettier/prettier": "error",
},
}
2 changes: 1 addition & 1 deletion plugins/publisher-main/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# publisher-main


main module for publisher

## Usage

Expand Down
10 changes: 6 additions & 4 deletions plugins/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
"name": "publisher-main",
"private": true,
"version": "1.1.3",
"type": "module",
"type": "commonjs",
"scripts": {
"dev": "vite",
"serve": "vite",
"dev": "vite build --watch",
"build": "vite build",
"start": "vite preview",
"test": "vitest --watch",
"syncVersion": "echo 'syncVersion in main'"
},
"devDependencies": {
"@terwer/eslint-config-custom": "latest",
"@terwer/vite-config-custom": "latest"
"@terwer/eslint-config-custom": "^1.2.0",
"@terwer/vite-config-custom": "^0.4.0",
"siyuan": "^0.7.1"
}
}
Binary file added plugins/publisher-main/public/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plugins/publisher-main/public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "publish-tool",
"author": "terwer",
"url": "https://github.com/terwer/siyuan-plugin-publisher",
"version": "1.1.2",
"version": "1.1.3",
"displayName": {
"default": "Publish Tool",
"zh_CN": "发布工具"
Expand Down
Binary file added plugins/publisher-main/public/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions plugins/publisher-main/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { describe, expect, it } from "vitest"
import init from "./index"
import { describe, it } from "vitest"

describe("publisher-main", () => {
it("index", () => {
expect(init()).toBe("ok")
describe("index", () => {
it("test index", () => {
console.log("hello")
})
})
10 changes: 6 additions & 4 deletions plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const init = () => {
return "ok"
}
import { Plugin } from "siyuan"

export default init
export default class PluginSample extends Plugin {
onload() {
console.log("Publish Tool loaded2333")
}
}
28 changes: 21 additions & 7 deletions plugins/publisher-main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Node",
// "allowImportingTsExtensions": true,
Expand All @@ -14,15 +17,26 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

"types": ["node", "vite/client"]
"types": [
"node",
"vite/client"
]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"references": [
{
"path": "./tsconfig.node.json"
}
],
"root": "."
}
131 changes: 87 additions & 44 deletions plugins/publisher-main/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,106 @@
/// <reference types="vitest" />

import { resolve } from "path"
import { defineConfig } from "vite"
import { join } from "path"
import { viteStaticCopy } from "vite-plugin-static-copy"
// import viteTsConfigPaths from "vite-tsconfig-paths"
import dts from "vite-plugin-dts"
import minimist from "minimist"
import livereload from "rollup-plugin-livereload"

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/publish-tool"
const distDir = isWatch ? devDistDir : "./dist"

console.log("isWatch=>", isWatch)
console.log("distDir=>", distDir)

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
dts({
entryRoot: "src",
tsConfigFilePath: join(__dirname, "tsconfig.json"),
skipDiagnostics: true,
}),

// viteTsConfigPaths({
// root: "../../",
// }),

viteStaticCopy({
targets: [
{
src: "README.md",
dest: "./",
},
],
}),
],

// Uncomment this if you are using workers.
// worker: {
// plugins: [
// viteTsConfigPaths({
// root: '../../',
// }),
// ],
// },

// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
// 项目根目录
// root: "./",

// 项目部署的基础路径
// base: "",

// 静态资源服务文件夹
// publicDir: "public",

build: {
// 浏览器兼容性 ‘esnext’ | 'modules'
// https://vitejs.dev/config/build-options.html#build-target
// target: "modules",

// 输出路径
outDir: distDir,

// 生成静态资源的存放路径
// assetsDir: "./assets",
// 小于此阈值的导入或引用资源将内联为 base64 编码, 以避免额外的http请求, 设置为 0, 可以完全禁用此项,
assetsInlineLimit: 4096,
// 启动 / 禁用 CSS 代码拆分
cssCodeSplit: true,
// 构建后是否生成 source map 文件
sourcemap: false,

// 设置为 false 可以禁用最小化混淆
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// 不压缩,用于调试
minify: isWatch ? false : "terser",
terserOptions: {
compress: {
// 生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},

lib: {
// Could also be a dictionary or array of multiple entry points.
entry: "src/index.ts",
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/index.ts"),
// the proper extensions will be added
fileName: "index",
// Change this to the formats you want to support.
// Don't forgot to update your package.json as well.
formats: ["es"],
formats: ["cjs"],
},

rollupOptions: {
// External packages that should not be bundled into your library.
external: [],
plugins: [...(isWatch ? [livereload(devDistDir)] : [])] as Plugin[],

// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["siyuan"],

output: {
chunkFileNames: "static/js/[name]-[hash].js",
// entryFileNames: "static/js/[name]-[hash].js",
entryFileNames: "[name].js",
assetFileNames: "static/[ext]/[name]-[hash].[ext]",
manualChunks(id) {
if (id.includes("node_modules")) {
let arr = id.toString().split("node_modules/")[1].split("/")
// pnpm单独处理
if (id.includes(".pnpm")) {
arr = id.toString().split(".pnpm/")[1].split("/")
}
const dep = arr[0].split("@")[0].replace(/\./g, "-")
// console.log("id=>", id)
// console.log("dep=>", dep)
if (dep !== "") {
return "vendor_" + dep
}
return "vendor"
}
},
},
},
},

test: {
globals: true,
// environment: "node",
environment: "jsdom",
// setupFiles: ["./setup.ts"],
deps: {
// inline: [],
},
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
},
})

0 comments on commit bc7b5cb

Please sign in to comment.