lvyjs 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/env.d.ts CHANGED
@@ -7,6 +7,14 @@ declare module '*.scss' {
7
7
  const src: string
8
8
  export default src
9
9
  }
10
+ declare module '*.less' {
11
+ const src: string
12
+ export default src
13
+ }
14
+ declare module '*.sass' {
15
+ const src: string
16
+ export default src
17
+ }
10
18
 
11
19
  // images
12
20
  declare module '*.png' {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -11,24 +11,15 @@
11
11
  "@rollup/plugin-commonjs": "^28.0.0",
12
12
  "@rollup/plugin-json": "^6.1.0",
13
13
  "@rollup/plugin-typescript": "^11.1.6",
14
+ "@rollup/pluginutils": "^5.1.3",
14
15
  "autoprefixer": "^10.4.20",
15
- "cssnano": "^7.0.6",
16
16
  "esbuild": "^0.24.0",
17
- "logger": "^0.0.1",
18
17
  "postcss": "^8.4.47",
19
- "postcss-cli": "^11.0.0",
20
18
  "postcss-import": "^16.1.0",
21
- "postcss-nested": "^6.2.0",
22
- "postcss-sass": "^0.5.0",
23
- "postcss-scss": "^4.0.9",
24
- "postcss-simple-vars": "^7.0.1",
25
- "postcss-styled": "^0.34.0",
26
- "postcss-syntax": "^0.36.2",
27
19
  "postcss-url": "^10.1.3",
28
20
  "rollup": "^4.18.1",
29
21
  "rollup-plugin-dts": "^6.1.1",
30
22
  "rollup-plugin-styles": "^4.0.0",
31
- "sass": "^1.79.4",
32
23
  "tailwindcss": "^3.4.3",
33
24
  "tsx": "^4.19.1",
34
25
  "typescript": "^5.5.3"
@@ -1,4 +0,0 @@
1
- const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/
2
- const cssReg = /\.(css|scss|less|sass|less)$/
3
-
4
- export { assetsReg, cssReg }
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * @param input
4
- * @returns
5
- */
6
- declare const ESBuild: (input: string) => Promise<string>
7
-
8
- export { ESBuild }
@@ -1,62 +0,0 @@
1
- import esbuild from 'esbuild'
2
- import { esBuildCSS } from './plugins/css.js'
3
- import { esBuildAlias } from './plugins/alias.js'
4
- import { esBuildAsstes } from './plugins/Asstes.js'
5
-
6
- // 插件
7
- const plugins = []
8
- /**
9
- *
10
- */
11
- const initPlugins = () => {
12
- if (typeof global.lvyConfig?.alias != 'boolean') {
13
- plugins.push(esBuildAlias(global.lvyConfig.alias))
14
- }
15
- if (typeof global.lvyConfig?.assets != 'boolean') {
16
- plugins.push(esBuildAsstes(global.lvyConfig.assets))
17
- }
18
- if (typeof global.lvyConfig?.styles != 'boolean') {
19
- plugins.push(esBuildCSS(global.lvyConfig?.styles ?? {}))
20
- }
21
- }
22
- /**
23
- *
24
- * @param input
25
- * @returns
26
- */
27
- const ESBuild = async input => {
28
- // 如果没有配置
29
- if (!global.lvyConfig) global.lvyConfig = {}
30
- if (!global.lvyConfig.esbuild) global.lvyConfig.esbuild = {}
31
- // 没有插件时,检查是否有可用插件。
32
- if (plugins.length === 0) {
33
- // init plugisn
34
- await initPlugins()
35
- }
36
- const options = global.lvyConfig?.esbuild?.options ?? {}
37
- const pl = options?.plugins ?? []
38
- // 构建
39
- const result = await esbuild.build({
40
- // 入口文件
41
- entryPoints: [input],
42
- //
43
- bundle: true,
44
- // 平台
45
- platform: 'node',
46
- // 输出格式
47
- format: 'esm',
48
- // 不写入文件
49
- write: false,
50
- // 忽略所有外部依赖
51
- external: ['*'],
52
- ...options,
53
- plugins: [...plugins, ...pl]
54
- })
55
- if (!result.outputFiles) {
56
- return ''
57
- }
58
- // 返回结果
59
- return result.outputFiles.map(file => new TextDecoder().decode(file.contents)).join('\n')
60
- }
61
-
62
- export { ESBuild }
@@ -1,26 +0,0 @@
1
- import { assetsReg } from '../config.js'
2
- import { generateModuleContent } from '../utils/content.js'
3
-
4
- /**
5
- *
6
- * @param param0
7
- */
8
- const esBuildAsstes = optoins => {
9
- // 默认配置
10
- const filter = optoins?.filter ?? assetsReg
11
- // 返回插件
12
- return {
13
- name: 'assets',
14
- setup(build) {
15
- build.onLoad({ filter }, args => {
16
- const content = generateModuleContent(args.path)
17
- return {
18
- contents: content,
19
- loader: 'js'
20
- }
21
- })
22
- }
23
- }
24
- }
25
-
26
- export { esBuildAsstes }
@@ -1,41 +0,0 @@
1
- import { join, resolve } from 'path'
2
-
3
- /**
4
- *
5
- * @param alias
6
- * @returns
7
- */
8
- const esBuildAlias = alias => {
9
- const entries = alias?.entries
10
- return {
11
- name: 'alias',
12
- setup(build) {
13
- // 解析路径时使用 entries
14
- if (entries) {
15
- build.onResolve({ filter: /.*/ }, args => {
16
- const url = args.path
17
- for (const { find, replacement } of entries) {
18
- if (typeof find === 'string' && url.startsWith(find)) {
19
- // 字符串匹配
20
- const resolvedPath = join(replacement, url.slice(find.length))
21
- const absolutePath = resolve(resolvedPath)
22
- return {
23
- path: absolutePath
24
- }
25
- } else if (find instanceof RegExp && find.test(url)) {
26
- // 正则匹配
27
- const resolvedPath = url.replace(find, replacement)
28
- const absolutePath = resolve(resolvedPath)
29
- return {
30
- path: absolutePath
31
- }
32
- }
33
- }
34
- return null
35
- })
36
- }
37
- }
38
- }
39
- }
40
-
41
- export { esBuildAlias }
@@ -1,6 +0,0 @@
1
- type ESBuildCSSOptions = {
2
- filter?: RegExp
3
- configPath?: string
4
- }
5
-
6
- export type { ESBuildCSSOptions }
@@ -1,27 +0,0 @@
1
- import { generateCSSModuleContent } from '../utils/content.js'
2
- import { cssReg } from '../config.js'
3
-
4
- /**
5
- * css资源处理插件
6
- * @param param0
7
- * @returns
8
- */
9
- const esBuildCSS = optoins => {
10
- const filter = optoins?.filter || cssReg
11
- // 返回插件
12
- return {
13
- name: 'css-loader',
14
- setup(build) {
15
- // 加载 CSS/SCSS 文件
16
- build.onLoad({ filter }, args => {
17
- const contents = generateCSSModuleContent(args.path)
18
- return {
19
- contents: contents,
20
- loader: 'js'
21
- }
22
- })
23
- }
24
- }
25
- }
26
-
27
- export { esBuildCSS }
@@ -1,59 +0,0 @@
1
- import { join } from 'path'
2
- import crypto from 'node:crypto'
3
-
4
- /**
5
- * @param inputPath
6
- * @returns
7
- */
8
- const convertPath = inputPath => {
9
- return process.platform === 'win32' ? inputPath.replace(/\\/g, '/') : inputPath
10
- }
11
- /**
12
- * 生成模块内容
13
- * @param {string} relativePath 相对路径
14
- */
15
- const generateModuleContent = relativePath => {
16
- const contents = [
17
- 'const createUrl = (basePath, path) => {',
18
- "const platform = ['linux', 'android', 'darwin'];",
19
- 'const T = platform.includes(process.platform);',
20
- 'const reg = T ? /^file:\\/\\// : /^file:\\/\\/\\//;',
21
- "return new URL(path, basePath).href.replace(reg, '');",
22
- '};',
23
- `const fileUrl = createUrl(import.meta.url, '${convertPath(relativePath)}');`,
24
- 'export default fileUrl;'
25
- ].join('\n')
26
- return contents
27
- }
28
- const getRandomName = str => {
29
- // 使用 MD5 算法创建哈希对象
30
- const hash = crypto.createHash('md5')
31
- // 更新哈希对象内容
32
- hash.update(str)
33
- return hash.digest('hex')
34
- }
35
- const chache = {}
36
- /**
37
- *
38
- * @param fileUrl
39
- * @returns
40
- */
41
- const generateCSSModuleContent = pathURL => {
42
- const fileName = getRandomName(pathURL)
43
- const outputFileURL = convertPath(
44
- join(process.cwd(), 'node_modules', 'lvyjs', 'assets', `${fileName}.css`)
45
- )
46
- if (!chache[pathURL]) {
47
- global.lvyWorkerProt.postMessage({
48
- type: 'CSS_MODULE_GENERATED',
49
- payload: {
50
- from: pathURL,
51
- to: outputFileURL
52
- }
53
- })
54
- chache[pathURL] = true
55
- }
56
- return `export default "${outputFileURL}";`
57
- }
58
-
59
- export { generateCSSModuleContent, generateModuleContent }
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { Options, defineConfig, getOptions, initConfig, usePlugin } from './store.js'
2
- export { buildAndRun, buildJS } from './rullup/index.js'
3
- export { ESBuild } from './esbuild/index.js'
package/lib/index.js DELETED
@@ -1,42 +0,0 @@
1
- import { buildAndRun } from './rullup/index.js'
2
- export { buildJS } from './rullup/index.js'
3
- import { initConfig } from './store.js'
4
- export { defineConfig, getOptions, usePlugin } from './store.js'
5
- export { ESBuild } from './esbuild/index.js'
6
-
7
- /**
8
- * @param input
9
- */
10
- const onDev = async () => {
11
- const apps = []
12
- if (Array.isArray(global.lvyConfig?.plugins)) {
13
- // 修改config
14
- for (const plugin of global.lvyConfig.plugins) {
15
- if (!plugin) {
16
- continue
17
- }
18
- apps.push(plugin(global.lvyConfig))
19
- }
20
- }
21
- // 执行loader
22
- await import('./main.js')
23
- //
24
- for (const app of apps) {
25
- if (!app) {
26
- continue
27
- }
28
- if (typeof app == 'function') app(global.lvyConfig)
29
- }
30
- }
31
- const main = async () => {
32
- if (process.argv.includes('--lvy-dev')) {
33
- await initConfig()
34
- onDev()
35
- } else if (process.argv.includes('--lvy-build')) {
36
- await initConfig()
37
- buildAndRun()
38
- }
39
- }
40
- main()
41
-
42
- export { buildAndRun, initConfig }
package/lib/loader.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { MessagePort } from 'worker_threads'
2
-
3
- declare global {
4
- var lvyWorkerProt: MessagePort
5
- }
6
- declare function initialize({ port, lvyConfig }: { port: any; lvyConfig: any }): Promise<void>
7
- /**
8
- * @param url
9
- * @param context
10
- * @param defaultLoad
11
- * @returns
12
- */
13
- declare const load: (url: any, context: any, defaultLoad: any) => Promise<any>
14
-
15
- export { initialize, load }
package/lib/loader.js DELETED
@@ -1,31 +0,0 @@
1
- import { ESBuild } from './esbuild/index.js'
2
-
3
- const platform = ['win32'].includes(process.platform)
4
- const reg = platform ? /^file:\/\/\// : /^file:\/\//
5
- const nodeReg = /(node_modules|node_|node:)/
6
- const jsReg = /\.(js|ts|jsx|tsx)$/
7
- async function initialize({ port, lvyConfig }) {
8
- global.lvyConfig = lvyConfig
9
- global.lvyWorkerProt = port
10
- }
11
- /**
12
- * @param url
13
- * @param context
14
- * @param defaultLoad
15
- * @returns
16
- */
17
- const load = async (url, context, defaultLoad) => {
18
- if (nodeReg.test(url)) {
19
- return defaultLoad(url, context)
20
- }
21
- if (!jsReg.test(url)) {
22
- return defaultLoad(url, context)
23
- }
24
- const code = await ESBuild(url.replace(reg, ''))
25
- return defaultLoad(url, {
26
- format: 'module',
27
- source: code
28
- })
29
- }
30
-
31
- export { initialize, load }
package/lib/main.js DELETED
@@ -1,33 +0,0 @@
1
- import module from 'node:module'
2
- import { MessageChannel } from 'node:worker_threads'
3
- import { postCSS } from './postcss.js'
4
-
5
- if (!module.register) {
6
- throw new Error(
7
- `This version of Node.js (${process.version}) does not support module.register(). Please upgrade to Node v18.19 or v20.6 and above.`
8
- )
9
- }
10
- const { port1, port2 } = new MessageChannel()
11
- const cache = {}
12
- port1.on('message', msg => {
13
- if (msg.type == 'CSS_MODULE_GENERATED') {
14
- const { from, to } = msg.payload
15
- if (!cache[from]) {
16
- postCSS(from, to)
17
- cache[from] = true
18
- }
19
- } else if (msg.type == 'JS_MODULE_GENERATED');
20
- })
21
- // port1.unref()
22
- module.register('./loader.js', {
23
- parentURL: import.meta.url,
24
- data: {
25
- port: port2,
26
- lvyConfig: {
27
- alias: global.lvyConfig.alias,
28
- assets: global.lvyConfig.assets,
29
- styles: global.lvyConfig.styles
30
- }
31
- },
32
- transferList: [port2]
33
- })
package/lib/postcss.js DELETED
@@ -1,100 +0,0 @@
1
- import fs from 'fs'
2
- import postcss from 'postcss'
3
- import { createRequire } from 'module'
4
- import { join, resolve, dirname } from 'path'
5
-
6
- const require = createRequire(import.meta.url)
7
- const loadPostcssConfig = configPath => {
8
- const plugins = []
9
- let aliasEntries = []
10
- if (typeof global.lvyConfig?.alias != 'boolean') {
11
- aliasEntries = global.lvyConfig.alias?.entries || []
12
- }
13
- if (aliasEntries.length > 0) {
14
- // 创建 postcss-import 插件并配置别名解析
15
- try {
16
- plugins.push(
17
- require('postcss-import')({
18
- resolve: (id, basedir) => {
19
- // 检查别名
20
- for (const entry of aliasEntries) {
21
- if (id.startsWith(entry.find)) {
22
- const aliasedPath = id.replace(entry.find, entry.replacement)
23
- return resolve(basedir, aliasedPath) // 返回绝对路径
24
- }
25
- }
26
- return id // 默认返回原始路径
27
- }
28
- })
29
- )
30
- } catch (err) {
31
- console.error(err)
32
- }
33
- }
34
- try {
35
- if (fs.existsSync(configPath)) {
36
- const cfg = require(configPath)
37
- // 添加其他插件
38
- if (!Array.isArray(cfg.plugins)) {
39
- const keys = Object.keys(cfg.plugins)
40
- keys.forEach(key => {
41
- try {
42
- const pluginConfig = cfg.plugins[key]
43
- const plugin = require(key)
44
- if (typeof plugin === 'function') {
45
- plugins.push(plugin(pluginConfig))
46
- } else {
47
- throw new Error(`插件 ${key} 不是有效的 PostCSS 插件函数`)
48
- }
49
- } catch (err) {
50
- console.error(`加载 PostCSS 插件 ${key} 失败:`, err)
51
- }
52
- })
53
- } else {
54
- plugins.push(...cfg.plugins)
55
- }
56
- return { plugins }
57
- } else {
58
- throw new Error(`未找到 PostCSS 配置文件: ${configPath}`)
59
- }
60
- } catch (err) {
61
- console.error('加载 PostCSS 配置失败:', err)
62
- return { plugins }
63
- }
64
- }
65
- const postCSS = (inputPath, outputPath) => {
66
- const configPath = join(process.cwd(), 'postcss.config.cjs')
67
- const postcssConfig = loadPostcssConfig(configPath)
68
- const readAndProcessCSS = async () => {
69
- const css = fs.readFileSync(inputPath, 'utf-8')
70
- fs.mkdirSync(dirname(outputPath), { recursive: true })
71
- const result = await postcss(postcssConfig.plugins).process(css, {
72
- from: inputPath,
73
- to: outputPath
74
- })
75
- fs.writeFileSync(outputPath, result.css)
76
- if (result.warnings().length) {
77
- result.warnings().forEach(warn => {
78
- console.warn(warn.toString())
79
- })
80
- }
81
- const dependencies = result.messages
82
- .filter(msg => msg.type === 'dependency')
83
- .map(msg => msg.file)
84
- for (const dep of dependencies) {
85
- fs.watch(dep, eventType => {
86
- if (eventType === 'change') {
87
- readAndProcessCSS()
88
- }
89
- })
90
- }
91
- }
92
- readAndProcessCSS()
93
- fs.watch(inputPath, eventType => {
94
- if (eventType === 'change') {
95
- readAndProcessCSS()
96
- }
97
- })
98
- }
99
-
100
- export { postCSS }
@@ -1,17 +0,0 @@
1
- /**
2
- * 打包 JS
3
- * *** 注意 **
4
- * 和initConfig配合使用
5
- * **
6
- * 确保已经初始化了配置
7
- * @param inputs
8
- * @param output
9
- */
10
- declare const buildJS: (inputs: string[]) => Promise<void>
11
- /**
12
- *
13
- * @param script
14
- */
15
- declare function buildAndRun(): Promise<void>
16
-
17
- export { buildAndRun, buildJS }
@@ -1,127 +0,0 @@
1
- import { rollup } from 'rollup'
2
- import { join } from 'path'
3
- import typescript from '@rollup/plugin-typescript'
4
- import commonjs from '@rollup/plugin-commonjs'
5
- import json from '@rollup/plugin-json'
6
- import styles from 'rollup-plugin-styles'
7
- import { getScriptFiles } from './utils/files.js'
8
- import alias from '@rollup/plugin-alias'
9
- import { rollupStylesCSSImport } from './plugins/loader-css.js'
10
- import { rollupAssets } from './plugins/loader-files.js'
11
-
12
- /**
13
- * 用于忽略警告
14
- * @param warning
15
- * @param warn
16
- */
17
- const onwarn = (warning, warn) => {
18
- if (warning.code === 'UNRESOLVED_IMPORT') return
19
- warn(warning)
20
- }
21
- /**
22
- * 打包 JS
23
- * *** 注意 **
24
- * 和initConfig配合使用
25
- * **
26
- * 确保已经初始化了配置
27
- * @param inputs
28
- * @param output
29
- */
30
- const buildJS = async inputs => {
31
- if (!global.lvyConfig) global.lvyConfig = {}
32
- if (!global.lvyConfig.build) global.lvyConfig.build = {}
33
- // 插件
34
- const plugins = []
35
- if (typeof global.lvyConfig?.alias !== 'boolean') {
36
- plugins.push(alias(global.lvyConfig?.alias ?? {}))
37
- }
38
- if (typeof global.lvyConfig?.assets !== 'boolean') {
39
- plugins.push(rollupAssets(global.lvyConfig?.assets ?? {}))
40
- }
41
- if (typeof global.lvyConfig?.styles !== 'boolean') {
42
- if (!global.lvyConfig.alias) global.lvyConfig.alias = {}
43
- const newAlias = val => {
44
- const alias = {}
45
- // 遍历 entries 数组
46
- val.entries.forEach(entry => {
47
- alias[entry.find] = entry.replacement
48
- })
49
- return alias
50
- }
51
- plugins.push(
52
- styles({
53
- alias: newAlias(global.lvyConfig?.alias),
54
- mode: ['inject', () => '']
55
- })
56
- )
57
- plugins.push(rollupStylesCSSImport(global.lvyConfig.styles))
58
- }
59
- plugins.push(json())
60
- if (typeof global.lvyConfig.build != 'boolean') {
61
- //
62
- for (const key in global.lvyConfig.build) {
63
- if (typeof global.lvyConfig.build[key] == 'boolean') {
64
- continue
65
- }
66
- if (key == 'commonjs' && !global.lvyConfig.build['@rollup/plugin-commonjs']) {
67
- plugins.push(commonjs(global.lvyConfig.build[key]))
68
- } else if (key == 'typescript' && !global.lvyConfig.build['@rollup/plugin-typescript']) {
69
- plugins.push(typescript(global.lvyConfig.build[key]))
70
- } else if (key == 'OutputOptions') {
71
- continue
72
- } else if (key == 'RollupOptions') {
73
- continue
74
- }
75
- }
76
- // 如果不存在这些配置
77
- const keys = ['commonjs', 'typescript']
78
- for (const key of keys) {
79
- // 如果是布尔值
80
- if (typeof global.lvyConfig.build[key] == 'boolean') {
81
- continue
82
- }
83
- // 存在这些配置
84
- if (global.lvyConfig.build[key]) {
85
- continue
86
- }
87
- //
88
- if (key === 'commonjs') {
89
- plugins.push(commonjs())
90
- } else if (key === 'typescript') {
91
- plugins.push(typescript())
92
- }
93
- }
94
- }
95
- const RollupOptions = global.lvyConfig?.build?.RollupOptions ?? {}
96
- const OutputOptions = global.lvyConfig?.build?.OutputOptions ?? []
97
- // build
98
- const bundle = await rollup({
99
- input: inputs,
100
- plugins: [...plugins],
101
- onwarn: onwarn,
102
- ...RollupOptions
103
- })
104
- // 写入输出文件
105
- await bundle.write({
106
- dir: 'lib',
107
- format: 'es',
108
- sourcemap: false,
109
- preserveModules: true,
110
- assetFileNames: 'assets/[name]-[hash][extname]',
111
- ...OutputOptions
112
- })
113
- }
114
- /**
115
- *
116
- * @param script
117
- */
118
- async function buildAndRun() {
119
- if (!global.lvyConfig) global.lvyConfig = {}
120
- if (!global.lvyConfig.build) global.lvyConfig.build = {}
121
- // rollup 配置
122
- let inputDir = global.lvyConfig?.build?.OutputOptions?.input ?? 'src'
123
- const inputFiles = getScriptFiles(join(process.cwd(), inputDir))
124
- await buildJS(inputFiles)
125
- }
126
-
127
- export { buildAndRun, buildJS }
@@ -1,4 +0,0 @@
1
- const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/
2
- const cssReg = /\.(css|scss|less|sass|less)$/
3
-
4
- export { assetsReg, cssReg }
@@ -1,58 +0,0 @@
1
- import { createFilter } from '@rollup/pluginutils'
2
- import { resolve, dirname, basename } from 'node:path'
3
- import { cssReg } from './config.js'
4
-
5
- /**
6
- *
7
- * @returns
8
- */
9
- const rollupStylesCSSImport = options => {
10
- const include = options?.filter ?? cssReg
11
- const filter = createFilter(include, null)
12
- return {
13
- name: 'c-css',
14
- resolveId(source, importer) {
15
- if (filter(source) && importer) {
16
- return resolve(dirname(importer), source)
17
- }
18
- },
19
- load(id) {
20
- if (filter(id)) this.addWatchFile(resolve(id))
21
- return null
22
- },
23
- async transform(code, id) {
24
- if (!filter(id)) return null
25
- // 删除 export default css
26
- const codex = code.replace(/(export|default css)/g, '')
27
- // 使用 eval 执行代码并获取默认导出的值
28
- const evalCode = `
29
- (() => {
30
- ${codex}
31
- return css;
32
- })()
33
- `
34
- // 得到css变量的值
35
- const csscode = eval(evalCode)
36
- // 确保最后生产的css文件
37
- const refeId = this.emitFile({
38
- // 属于静态资源
39
- type: 'asset',
40
- name: basename(`${id}.css`),
41
- // 内容
42
- source: csscode
43
- })
44
- const contents = `
45
- const createUrl = () => {
46
- const platform = ['linux', 'android', 'darwin'];
47
- const T = platform.includes(process.platform);
48
- const reg = T ? /^file:\\/\\// : /^file:\\/\\/\\//
49
- return import.meta.ROLLUP_FILE_URL_${refeId}.replace(reg, '')
50
- };
51
- export default createUrl();
52
- `
53
- return contents
54
- }
55
- }
56
- }
57
-
58
- export { rollupStylesCSSImport }
@@ -1,40 +0,0 @@
1
- import { resolve, dirname, basename } from 'path'
2
- import { readFileSync } from 'fs'
3
- import { assetsReg } from './config.js'
4
-
5
- /**
6
- * @param {Object} options
7
- * @returns {Object}
8
- */
9
- const rollupAssets = options => {
10
- const { filter = assetsReg } = options ?? {}
11
- return {
12
- name: 'rollup-node-files',
13
- resolveId(source, importer) {
14
- if (filter.test(source) && importer) {
15
- return resolve(dirname(importer), source)
16
- }
17
- },
18
- load(id) {
19
- if (filter.test(id)) {
20
- const referenceId = this.emitFile({
21
- type: 'asset',
22
- name: basename(id),
23
- source: readFileSync(id)
24
- })
25
- const content = [
26
- 'const createUrl = () => {',
27
- "const platform = ['linux', 'android', 'darwin'];",
28
- 'const T = platform.includes(process.platform);',
29
- 'const reg = T ? /^file:\\/\\// : /^file:\\/\\/\\//',
30
- 'return import.meta.ROLLUP_FILE_URL_' + referenceId + ".replace(reg, '')",
31
- '};',
32
- 'export default createUrl();'
33
- ].join('\n')
34
- return content
35
- }
36
- }
37
- }
38
- }
39
-
40
- export { rollupAssets }
@@ -1,27 +0,0 @@
1
- import { join } from 'path'
2
- import { readdirSync } from 'fs'
3
-
4
- /**
5
- * 获取指定目录下的所有 ts、js、jsx、tsx 文件
6
- * @param dir 目录路径
7
- * @returns 文件路径数组
8
- */
9
- const getScriptFiles = dir => {
10
- const results = []
11
- const list = readdirSync(dir, { withFileTypes: true })
12
- list.forEach(item => {
13
- const fullPath = join(dir, item.name)
14
- if (item.isDirectory()) {
15
- results.push(...getScriptFiles(fullPath))
16
- } else if (
17
- item.isFile() &&
18
- /\.(ts|js|jsx|tsx)$/.test(item.name) &&
19
- !item.name.endsWith('.d.ts')
20
- ) {
21
- results.push(fullPath)
22
- }
23
- })
24
- return results
25
- }
26
-
27
- export { getScriptFiles }
package/lib/store.d.ts DELETED
@@ -1,111 +0,0 @@
1
- import { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
2
- import { RollupTypescriptOptions } from '@rollup/plugin-typescript'
3
- import { SameShape, BuildOptions } from 'esbuild'
4
- import { RollupOptions, OutputOptions } from 'rollup'
5
-
6
- interface Alias {
7
- find: string | RegExp
8
- replacement: string
9
- }
10
- type Options = {
11
- /**
12
- * 配置调整机及其回调插件
13
- */
14
- plugins?: ((options: Options) => ((options: Options) => void) | void | undefined | null)[]
15
- /**
16
- * 别名
17
- */
18
- alias?:
19
- | {
20
- /**
21
- * 别名规则
22
- */
23
- entries?: Alias[]
24
- }
25
- | false
26
- /**
27
- * 静态资源识别
28
- */
29
- assets?:
30
- | {
31
- /**
32
- * 过滤得到指定格式的文件识别之为静态资源
33
- */
34
- filter?: RegExp
35
- }
36
- | false
37
- styles?:
38
- | {
39
- /**
40
- * 过滤得到指定格式的文件识别之为静态资源
41
- */
42
- filter?: RegExp
43
- }
44
- | false
45
- /**
46
- * 运行时配置
47
- */
48
- esbuild?: {
49
- /**
50
- *
51
- */
52
- options?: SameShape<BuildOptions, BuildOptions>
53
- }
54
- /**
55
- * 打包时配置
56
- */
57
- build?:
58
- | {
59
- /**
60
- * cjs文件处理
61
- */
62
- commonjs?: RollupCommonJSOptions | false
63
- /**
64
- * ts配置
65
- */
66
- typescript?: RollupTypescriptOptions | false
67
- /**
68
- *
69
- */
70
- RollupOptions?: RollupOptions
71
- /**
72
- *
73
- */
74
- OutputOptions?: OutputOptions & {
75
- /**
76
- * 默认 src
77
- */
78
- input?: string
79
- }
80
- }
81
- | false
82
- }
83
- /**
84
- *
85
- * @param options
86
- * @returns
87
- */
88
- declare const usePlugin: (
89
- load: (options: Options) => ((options: Options) => void) | void | undefined | null
90
- ) => (options: Options) => ((options: Options) => void) | void | undefined | null
91
- /**
92
- *
93
- */
94
- declare global {
95
- var lvyConfig: Options
96
- }
97
- /**
98
- *
99
- */
100
- declare const initConfig: () => Promise<void>
101
- /**
102
- * @returns
103
- */
104
- declare const getOptions: () => Options
105
- /**
106
- * @param param0
107
- * @returns
108
- */
109
- declare const defineConfig: (optoins?: Options) => Options | undefined
110
-
111
- export { type Options, defineConfig, getOptions, initConfig, usePlugin }
package/lib/store.js DELETED
@@ -1,46 +0,0 @@
1
- import { existsSync } from 'fs'
2
- import { join } from 'path'
3
-
4
- /**
5
- *
6
- * @param options
7
- * @returns
8
- */
9
- const usePlugin = load => load
10
- /**
11
- *
12
- */
13
- const initConfig = async () => {
14
- if (!global.lvyConfig) global.lvyConfig = {}
15
- const files = [
16
- 'lvy.config.ts',
17
- 'lvy.config.js',
18
- 'lvy.config.mjs',
19
- 'lvy.config.cjs',
20
- 'lvy.config.tsx'
21
- ]
22
- let configDir = ''
23
- for (const file of files) {
24
- if (existsSync(file)) {
25
- configDir = file
26
- break
27
- }
28
- }
29
- if (configDir !== '') {
30
- const v = await import(`file://${join(process.cwd(), configDir)}`)
31
- if (v?.default) {
32
- global.lvyConfig = v.default
33
- }
34
- }
35
- }
36
- /**
37
- * @returns
38
- */
39
- const getOptions = () => global.lvyConfig
40
- /**
41
- * @param param0
42
- * @returns
43
- */
44
- const defineConfig = optoins => optoins
45
-
46
- export { defineConfig, getOptions, initConfig, usePlugin }