From 128edc5d63d8135574e8d44907a331e82a0e90d2 Mon Sep 17 00:00:00 2001 From: phy-lei <765373325@qq.com> Date: Fri, 19 Jan 2024 16:43:08 +0800 Subject: [PATCH] feat: init --- .gitignore | 41 ++++++++++++ .npmrc | 1 + jest.config.js | 5 ++ package.json | 63 ++++++++++++++++++ pnpm-lock.yaml | 38 +++++++++++ rollup.config.js | 58 ++++++++++++++++ src/api-loader.ts | 76 +++++++++++++++++++++ src/custom-render/h.ts | 129 ++++++++++++++++++++++++++++++++++++ src/custom-render/index.ts | 2 + src/custom-render/render.ts | 64 ++++++++++++++++++ src/custom-render/utils.ts | 102 ++++++++++++++++++++++++++++ src/index.ts | 67 +++++++++++++++++++ src/loader-meta.ts | 26 ++++++++ src/runtime/connect.ts | 119 +++++++++++++++++++++++++++++++++ src/runtime/dom.ts | 14 ++++ src/runtime/index.ts | 1 + src/webpack.h5.ts | 21 ++++++ src/webpack.mini.ts | 9 +++ tsconfig.json | 20 ++++++ 19 files changed, 856 insertions(+) create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100644 rollup.config.js create mode 100644 src/api-loader.ts create mode 100644 src/custom-render/h.ts create mode 100644 src/custom-render/index.ts create mode 100644 src/custom-render/render.ts create mode 100644 src/custom-render/utils.ts create mode 100644 src/index.ts create mode 100644 src/loader-meta.ts create mode 100644 src/runtime/connect.ts create mode 100644 src/runtime/dom.ts create mode 100644 src/runtime/index.ts create mode 100644 src/webpack.h5.ts create mode 100644 src/webpack.mini.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1e88aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + + + +# parcel-bundler cache (https://parceljs.org/) +.cache + +dist/ +deploy_versions/ +.temp/ +.rn_temp/ +.DS_Store +.swc +.yalc +yalc.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..5660f81 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org/ \ No newline at end of file diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..b413e10 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..c700595 --- /dev/null +++ b/package.json @@ -0,0 +1,63 @@ +{ + "name": "tarojs-plugin-solid", + "version": "0.0.1", + "description": "taro插件,支持使用 Solid 开发小程序", + "main": "lib/index.js", + "files": [ + "lib" + ], + "scripts": { + "build": "rollup -c --bundleConfigAsCjs", + "test": "jest" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/phy-lei/tarojs-plugin-solid" + }, + "keywords": [ + "taro", + "taro3", + "tarojs", + "solid", + "solidjs" + ], + "author": "phy-lei", + "license": "MIT", + "bugs": { + "url": "https://github.com/phy-lei/tarojs-plugin-solid/issues" + }, + "homepage": "https://github.com/phy-lei/tarojs-plugin-solid#readme", + "peerDependencies": { + "@tarojs/runtime": ">=3.0.0", + "@tarojs/service": ">=3.0.0", + "@tarojs/shared": ">=3.0.0", + "@tarojs/webpack5-runner": ">=3.0.0", + "solid-js": ">=1" + }, + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "public" + }, + "volta": { + "node": "18.17.1", + "npm": "9.6.7" + }, + "dependencies": { + "solid-js": "^1.8.11" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-node-resolve": "^15.2.3", + "@tarojs/runtime": "^3.6.22", + "@tarojs/service": "^3.6.22", + "@tarojs/shared": "^3.6.22", + "@tarojs/webpack5-runner": "^3.6.22", + "@types/jest": "^29.5.11", + "jest": "^29.7.0", + "rollup": "^4.9.5", + "rollup-plugin-node-externals": "^6.1.2", + "rollup-plugin-ts": "^3.4.5", + "ts-jest": "^29.1.1", + "typescript": "^5.3.3" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..c3be0af --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,38 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +dependencies: + solid-js: + specifier: ^1.8.11 + version: 1.8.11 + +packages: + + /csstype@3.1.3: + resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + dev: false + + /seroval-plugins@1.0.4(seroval@1.0.4): + resolution: {integrity: sha512-DQ2IK6oQVvy8k+c2V5x5YCtUa/GGGsUwUBNN9UqohrZ0rWdUapBFpNMYP1bCyRHoxOJjdKGl+dieacFIpU/i1A==} + engines: {node: '>=10'} + peerDependencies: + seroval: ^1.0 + dependencies: + seroval: 1.0.4 + dev: false + + /seroval@1.0.4: + resolution: {integrity: sha512-qQs/N+KfJu83rmszFQaTxcoJoPn6KNUruX4KmnmyD0oZkUoiNvJ1rpdYKDf4YHM05k+HOgCxa3yvf15QbVijGg==} + engines: {node: '>=10'} + dev: false + + /solid-js@1.8.11: + resolution: {integrity: sha512-WdwmER+TwBJiN4rVQTVBxocg+9pKlOs41KzPYntrC86xO5sek8TzBYozPEZPL1IRWDouf2lMrvSbIs3CanlPvQ==} + dependencies: + csstype: 3.1.3 + seroval: 1.0.4 + seroval-plugins: 1.0.4(seroval@1.0.4) + dev: false diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d503a73 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,58 @@ +import * as path from 'path'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import { externals } from 'rollup-plugin-node-externals'; +import ts from 'rollup-plugin-ts'; + +const base = { + plugins: [ + commonjs(), + nodeResolve(), + externals({ + include: [ + '@tarojs/runtime', + '@tarojs/service', + '@tarojs/shared', + '@tarojs/webpack5-runner', + ], + }), + ts(), + ], +}; + +// 供 CLI 编译时使用的 Taro 插件入口 +const compileConfig = { + input: path.join(__dirname, 'src/index.ts'), + output: { + file: path.join(__dirname, 'dist/index.js'), + format: 'cjs', + sourcemap: true, + exports: 'named', + }, + ...base, +}; + +// 供 Loader 使用的运行时入口 +const runtimeConfig = { + input: path.join(__dirname, 'src/runtime/index.ts'), + output: { + file: path.join(__dirname, 'dist/runtime.js'), + format: 'es', + sourcemap: true, + }, + ...base, +}; + +// Solid Loader +const loaderConfig = { + input: path.join(__dirname, 'src/api-loader.ts'), + output: { + file: path.join(__dirname, 'dist/api-loader.js'), + format: 'cjs', + sourcemap: true, + exports: 'auto', + }, + ...base, +}; + +export default [compileConfig, runtimeConfig, loaderConfig]; diff --git a/src/api-loader.ts b/src/api-loader.ts new file mode 100644 index 0000000..f818d82 --- /dev/null +++ b/src/api-loader.ts @@ -0,0 +1,76 @@ +export default function (str: string) { + return `import { + useAddToFavorites, + useDidHide, + useDidShow, + useError, + useLaunch, + useLoad, + useOptionMenuClick, + usePageNotFound, + usePageScroll, + usePullDownRefresh, + usePullIntercept, + useReachBottom, + useReady, + useResize, + useRouter, + useSaveExitState, + useShareAppMessage, + useShareTimeline, + useTabItemTap, + useTitleClick, + useScope, + useUnload +} from 'tarojs-plugin-solid/dist/runtime' +${str} + +taro.useAddToFavorites = useAddToFavorites +taro.useDidHide = useDidHide +taro.useDidShow = useDidShow +taro.useError = useError +taro.useLaunch = useLaunch +taro.useLoad = useLoad +taro.useOptionMenuClick = useOptionMenuClick +taro.usePageNotFound = usePageNotFound +taro.usePageScroll = usePageScroll +taro.usePullDownRefresh = usePullDownRefresh +taro.usePullIntercept = usePullIntercept +taro.useReachBottom = useReachBottom +taro.useReady = useReady +taro.useResize = useResize +taro.useRouter = useRouter +taro.useSaveExitState = useSaveExitState +taro.useShareAppMessage = useShareAppMessage +taro.useShareTimeline = useShareTimeline +taro.useTabItemTap = useTabItemTap +taro.useTitleClick = useTitleClick +taro.useScope = useScope +taro.useUnload = useUnload + +export { + useAddToFavorites, + useDidHide, + useDidShow, + useError, + useLaunch, + useLoad, + useOptionMenuClick, + usePageNotFound, + usePageScroll, + usePullDownRefresh, + usePullIntercept, + useReachBottom, + useReady, + useResize, + useRouter, + useSaveExitState, + useShareAppMessage, + useShareTimeline, + useTabItemTap, + useTitleClick, + useScope, + useUnload +} +` +} diff --git a/src/custom-render/h.ts b/src/custom-render/h.ts new file mode 100644 index 0000000..e276611 --- /dev/null +++ b/src/custom-render/h.ts @@ -0,0 +1,129 @@ +import { TaroNode } from '@tarojs/runtime' +import { createRenderEffect, onCleanup, splitProps, children as solidChildren, Accessor } from 'solid-js' +import { ResolvedChildren } from 'solid-js/types/reactive/signal' +import { createElement, createTextNode, effect, insert, insertNode, setProp } from './render' + +export type Component = (props?: any) => TaroNode + +type Children = + | undefined + | string + | number + | TaroNode + | TaroNode[] + | Component + | Component[] + | Accessor + | (() => Component[]) + +export function h(com: string, props?: any, children?: Children) { + if (typeof com !== 'string') { + throw Error(`h function cant create ele for ${com}`) + } + const ele = createElement(com) + const [local, otherProps] = splitProps(props, ['ref', 'children']) + + setProps(ele, otherProps) + + if (local.ref) { + createRenderEffect(() => { + if (typeof local.ref === 'function') { + local.ref(ele) + } else { + local.ref = ele + } + }) + } + + // get 的处理 + if (local.hasOwnProperty('children')) { + const descriptor = Object.getOwnPropertyDescriptor(local, 'children') + if (descriptor?.get) { + children = solidChildren(() => local.children) + } else { + children = local.children + } + } + insertNodes(ele, children) + + return ele +} + +function setProps(ele: TaroNode, otherProps) { + const desc = Object.getOwnPropertyDescriptors(otherProps) + const plain_keys = Object.keys(desc).filter((key) => { + if (desc[key].get) { + return false + } + return true + }) + const [plainProps, getterValues] = splitProps(otherProps, plain_keys) + + // 普通属性直接赋值 + if (Object.keys(plainProps)?.length) { + for (const key in plainProps) { + setProp(ele, key, plainProps[key]) + } + } + + // 特殊属性 放到createRenderEffect中 + if (Object.keys(getterValues)?.length) { + let preProps = {} as typeof getterValues + effect(() => { + for (const key in getterValues) { + const val = getterValues[key] + + if (val === preProps[key]) { + continue + } + setProp(ele, key, val, preProps[key]) + preProps[key] = val + } + }) + onCleanup(() => { + preProps = {} + }) + } +} + +function insertNodes(parent: TaroNode, children: Children) { + if (children === undefined) { + return + } + + let list = [] as TaroNode[] | (() => TaroNode)[] + if (!Array.isArray(children)) { + list = [children] as TaroNode[] | (() => TaroNode)[] + } else { + list = children + } + for (let i = 0; i < list.length; i++) { + const child = list[i] + const type = typeof child + if (type === 'function') { + insert(parent, child, null) + continue + } + if (Array.isArray(child)) { + insertNodes(parent, child) + continue + } + + if (child instanceof TaroNode) { + insertNode(parent, child) + continue + } + + if (type === 'string') { + const node = createTextNode(child as unknown as string) + insertNode(parent, node) + continue + } + + if (type === 'number' || type === 'boolean' || child instanceof Date || child instanceof RegExp) { + const node = createTextNode(child.toString()) + insertNode(parent, node) + continue + } + } +} diff --git a/src/custom-render/index.ts b/src/custom-render/index.ts new file mode 100644 index 0000000..911ad1e --- /dev/null +++ b/src/custom-render/index.ts @@ -0,0 +1,2 @@ +export * from './render' +export * from './h' \ No newline at end of file diff --git a/src/custom-render/render.ts b/src/custom-render/render.ts new file mode 100644 index 0000000..c8a5cb9 --- /dev/null +++ b/src/custom-render/render.ts @@ -0,0 +1,64 @@ +import { createRenderer } from 'solid-js/universal' +import { document, TaroElement, TaroNode, TaroText } from '@tarojs/runtime' +// import { setProperty } from './utils' +import { h } from './h' +const PROPERTIES = new Set(["className", "textContent"]); +export const { + render, + effect, + memo, + createComponent: _createComponent, + createElement, + createTextNode, + insertNode, + insert, + spread, + setProp, + mergeProps, + use +} = createRenderer({ + createElement(type: string) { + return document.createElement(type) + }, + createTextNode(text) { + return document.createTextNode(text) + }, + replaceText(textNode: TaroText, value) { + textNode.textContent = value + }, + setProperty(node: TaroElement, name: string, value, prev) { + if (name === "style") Object.assign(node.style, value); + else if (name.startsWith("on")) node[name.toLowerCase()] = value; + else if (PROPERTIES.has(name)) node[name] = value; + else node.setAttribute(name, value); + // setProperty(node, name, value, prev) + }, + insertNode(parent, node, anchor) { + parent.insertBefore(node, anchor) + }, + isTextNode(node: TaroNode) { + if (typeof node === 'string') { + return true + } + return node instanceof TaroText + }, + removeNode(parent: TaroElement, node: TaroElement) { + parent.removeChild(node) + }, + getParentNode(node: TaroNode) { + return node.parentNode || undefined + }, + getFirstChild(node: TaroElement) { + return node.firstChild || undefined + }, + getNextSibling(node: TaroElement) { + return node.nextSibling || undefined + }, +}) + +export const createComponent = (type, props) => { + if (typeof type === 'string') { + return h(type, props) + } + return _createComponent(type, props) +} diff --git a/src/custom-render/utils.ts b/src/custom-render/utils.ts new file mode 100644 index 0000000..e5b116d --- /dev/null +++ b/src/custom-render/utils.ts @@ -0,0 +1,102 @@ +import { TaroElement } from '@tarojs/runtime' +import { + capitalize, + internalComponents, + isFunction, + toCamelCase, +} from '@tarojs/shared' + +interface DangerouslySetInnerHTML { + __html?: string +} +type ClassList = { [key: string]: boolean }; + +function isEventName(s: string) { + return s.startsWith('on') +} + +export function setProperty( + dom: TaroElement, + name: string, + value: any, + oldValue?: any +) { + + if (name === 'key' || name === 'children' || name === 'ref') { + // skip + } else if (name === 'classList') { + const map = diffClassList(value as ClassList, oldValue as ClassList) + for (const key in map) { + if (key === '') { + continue + } + if (map[key]) { + dom.classList.add(key) + } else { + dom.classList.remove(key) + } + } + } else if (isEventName(name)) { + setEvent(dom, name, value, oldValue) + } else if (name === 'dangerouslySetInnerHTML') { + const newHtml = (value as DangerouslySetInnerHTML)?.__html ?? '' + const oldHtml = (oldValue as DangerouslySetInnerHTML)?.__html ?? '' + if (newHtml || oldHtml) { + if (oldHtml !== newHtml) { + dom.innerHTML = newHtml + } + } + } else if (!isFunction(value)) { + if (value == null) { + dom.removeAttribute(name) + } else { + dom.setAttribute(name, value as string) + } + } +} + +function diffClassList(newVal: ClassList, oldVal: ClassList) { + const result: ClassList = {} + for (const key in oldVal) { + if (newVal[key] !== oldVal[key]) { + result[key] = newVal[key] + } + } + for (const key in newVal) { + if (result.hasOwnProperty(key)) { + continue + } + result[key] = newVal[key] + } + return result +} + +function setEvent( + dom: TaroElement, + name: string, + value: unknown, + oldValue?: unknown +) { + const isCapture = name.endsWith('Capture') + let eventName = name.toLowerCase().slice(2) + if (isCapture) { + eventName = eventName.slice(0, -7) + } + + const compName = capitalize(toCamelCase(dom.tagName.toLowerCase())) + + if (eventName === 'click' && compName in internalComponents) { + eventName = 'tap' + } + + if (isFunction(value)) { + if (oldValue) { + dom.removeEventListener(eventName, oldValue as any, false) + dom.addEventListener(eventName, value, { isCapture, sideEffect: false }) + } else { + dom.addEventListener(eventName, value, isCapture) + } + } else { + dom.removeEventListener(eventName, oldValue as any) + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..e419fb4 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,67 @@ +import type { IPluginContext } from '@tarojs/service' +import { modifyH5WebpackChain } from './webpack.h5' +import { modifyMiniWebpackChain } from './webpack.mini' + +try { + const configSchema = require('@tarojs/cli/dist/doctor/configSchema') + const Joi = require('joi') + + configSchema.default.$_terms.keys.forEach(term => { + if (term.key === 'framework') { + term.schema = Joi.any().valid('nerv', 'react', 'preact', 'vue', 'vue3', 'solid').required() + } + }) +} catch { + // ignore +} + +export default (ctx: IPluginContext) => { + const { framework } = ctx.initialConfig + if ((framework as (typeof framework) | 'solid') !== 'solid') { + return + } + + ctx.modifyWebpackChain(({ chain }) => { + chain + .plugin('definePlugin') + .tap(args => { + const config = args[0] + config.__TARO_FRAMEWORK__ = `"${framework}"` + return args + }) + + if (process.env.TARO_ENV === 'h5') { + modifyH5WebpackChain(chain) + } else { + modifyMiniWebpackChain(chain) + } + }) + + ctx.modifyRunnerOpts(({ opts }) => { + if (!opts.compiler) { + return + } + + if (typeof opts.compiler === 'string') { + opts.compiler = { + type: opts.compiler + } + } + + const { compiler } = opts + + if (compiler.type === 'webpack5') { + // 提供给 webpack5 依赖预编译收集器的第三方依赖 + const deps = ["tarojs-plugin-solid/dist/runtime"] + compiler.prebundle ||= {} + const prebundleOptions = compiler.prebundle + prebundleOptions.include ||= [] + prebundleOptions.include = prebundleOptions.include.concat(deps); + prebundleOptions.exclude ||= [] + + prebundleOptions.esbuild ||= {} + const esbuildConfig = prebundleOptions.esbuild + esbuildConfig.plugins ||= [] + } + }) +} diff --git a/src/loader-meta.ts b/src/loader-meta.ts new file mode 100644 index 0000000..0b14b8f --- /dev/null +++ b/src/loader-meta.ts @@ -0,0 +1,26 @@ +interface ILoaderMeta { + importFrameworkStatement: string + mockAppStatement: string + frameworkArgs: string + creator: string + creatorLocation: string + extraImportForWeb: string + execBeforeCreateWebApp: string + importFrameworkName: string + isNeedRawLoader?: boolean + modifyConfig?: (config: Record, source: string) => void +} + +export function getLoaderMeta(): ILoaderMeta { + return { + importFrameworkStatement: '', + mockAppStatement: '', + frameworkArgs: 'config', + creator: 'createSolidApp', + creatorLocation: 'tarojs-plugin-solid/dist/runtime', + importFrameworkName: '', + isNeedRawLoader: true, + extraImportForWeb: '', + execBeforeCreateWebApp: '' + } +} diff --git a/src/runtime/connect.ts b/src/runtime/connect.ts new file mode 100644 index 0000000..724d578 --- /dev/null +++ b/src/runtime/connect.ts @@ -0,0 +1,119 @@ +import { + AppInstance, + Current, + document, + getPageInstance, + injectPageInstance, + Instance, + PageLifeCycle, + PageProps, + ReactAppInstance, + TaroNode, +} from "@tarojs/runtime"; +import type { AppConfig } from "@tarojs/taro"; +import { For } from "solid-js"; +import { installGlobalShims } from './dom' +import { createComponent, render, h } from "../custom-render"; + +const { hooks } = require('@tarojs/shared') + +installGlobalShims() + +const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl').app + +let container: HTMLDivElement = null + +type Component = (props?: any) => TaroNode; + +export function createSolidApp(app: Component, config: AppConfig) { + const pages = new Map() + + const AppWrapper = () => { + return createComponent(app, { + children: createComponent(For as unknown as Component, { + get each() { + return pages; + }, + children: ({ id, component }) => { + const children = () => + createComponent(null, { + value: id, + children: () => { + injectPageInstance( + { id: id, type: "page" } as unknown as Instance, + id + ); + return createComponent(component, { + tid: id, + }); + }, + }); + + if (process.env.TARO_ENV === "h5") { + return h("div", { id, className: "taro_page" }, children); + } else { + return h("root", { id }, children); + } + }, + }), + }); + }; + + let appId = "app"; + if (process.env.TARO_ENV === "h5") { + appId = config?.appId || appId; + } + const container = document.getElementById(appId); + render(AppWrapper, container); + + + const appConfig = { + config, + + mount(Page, id, cb) { + + pages.set(id, Page) + cb() + }, + + unmount(id, cb) { + if (pages.has(id)) { + pages.get(id).$destroy() + } + cb() + }, + + [ONLAUNCH](options) { + if (process.env.TARO_ENV === 'h5') { + const appId = config?.appId || 'app' + container = document.getElementById(appId) + } + + app?.onLaunch?.(options) + }, + + [ONSHOW](options) { + app?.onShow?.(options) + }, + + [ONHIDE](options) { + app?.onHide?.(options) + }, + + onError(error) { + app?.onError?.(error) + }, + + onUnhandledRejection(error) { + app?.onUnhandledRejection?.(error) + }, + + onPageNotFound(res) { + app?.onPageNotFound?.(res) + } + } + + Current.app = appConfig + + return appConfig +} diff --git a/src/runtime/dom.ts b/src/runtime/dom.ts new file mode 100644 index 0000000..91b1fa1 --- /dev/null +++ b/src/runtime/dom.ts @@ -0,0 +1,14 @@ +// @ts-nocheck +export function installGlobalShims() { + let originCreateEvent = document.createEvent + + document.createEvent = function (type, node) { + const e = originCreateEvent(type, node) + e.initCustomEvent = (type, ignored1, ignored2, detail) => { + e.type = type + e.detail = detail + e.eventName = type + } + return e + } +} diff --git a/src/runtime/index.ts b/src/runtime/index.ts new file mode 100644 index 0000000..2130a30 --- /dev/null +++ b/src/runtime/index.ts @@ -0,0 +1 @@ +export * from './connect' diff --git a/src/webpack.h5.ts b/src/webpack.h5.ts new file mode 100644 index 0000000..48d77af --- /dev/null +++ b/src/webpack.h5.ts @@ -0,0 +1,21 @@ +import { getLoaderMeta } from './loader-meta' + +export function modifyH5WebpackChain(chain) { + chain.merge({ + module: { + rule: { + 'process-import-taro': { + test: /taro-h5[\\/]dist[\\/]index/, + loader: require.resolve('./api-loader'), + }, + }, + }, + }) + + + chain.plugin('mainPlugin') + .tap(args => { + args[0].loaderMeta = getLoaderMeta() + return args + }) +} diff --git a/src/webpack.mini.ts b/src/webpack.mini.ts new file mode 100644 index 0000000..a02abb7 --- /dev/null +++ b/src/webpack.mini.ts @@ -0,0 +1,9 @@ +import { getLoaderMeta } from './loader-meta' + +export function modifyMiniWebpackChain(chain) { + chain.plugin('miniPlugin') + .tap(args => { + args[0].loaderMeta = getLoaderMeta() + return args + }) +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2258f3f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "outDir": "lib", + "module": "CommonJS", + "sourceMap": true, + "allowSyntheticDefaultImports": true, + "experimentalDecorators": true, + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "noUnusedParameters": true, + "removeComments": false, + "resolveJsonModule": true, + "skipLibCheck": true, + "target": "ES6", + "lib": ["DOM"] + }, + "include": ["src"] +}