lvyjs 0.2.11 → 0.2.13
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/bin/index.js +5 -6
- package/lib/config.d.ts +6 -6
- package/lib/config.js +15 -15
- package/lib/content.js +37 -35
- package/lib/index.d.ts +11 -3
- package/lib/index.js +56 -58
- package/lib/loader.d.ts +6 -9
- package/lib/loader.js +51 -51
- package/lib/main.js +31 -29
- package/lib/postcss.js +170 -172
- package/lib/rullup/index.d.ts +3 -3
- package/lib/rullup/index.js +97 -105
- package/lib/rullup/plugins/loader-css.js +44 -46
- package/lib/rullup/plugins/loader-files.js +30 -30
- package/lib/rullup/utils/files.js +20 -19
- package/lib/store.d.ts +66 -48
- package/lib/store.js +25 -26
- package/lib/typing.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,56 +1,54 @@
|
|
|
1
|
-
import { createFilter } from '@rollup/pluginutils'
|
|
2
|
-
import { resolve, dirname, basename } from 'node:path'
|
|
3
|
-
import { stylesRegExp } from '../../config.js'
|
|
1
|
+
import { createFilter } from '@rollup/pluginutils'
|
|
2
|
+
import { resolve, dirname, basename } from 'node:path'
|
|
3
|
+
import { stylesRegExp } from '../../config.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
const rollupStylesCSSImport =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// 使用 eval 执行代码并获取默认导出的值
|
|
30
|
-
const evalCode = `
|
|
9
|
+
const rollupStylesCSSImport = options => {
|
|
10
|
+
const include = options?.filter ?? stylesRegExp
|
|
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 = `
|
|
31
29
|
(() => {
|
|
32
30
|
${codex}
|
|
33
31
|
return css;
|
|
34
32
|
})()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
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 reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
|
|
46
|
+
`const fileUrl = import.meta.ROLLUP_FILE_URL_${refeId}.replace(reg, '');`,
|
|
47
|
+
'export default fileUrl;'
|
|
48
|
+
].join('\n')
|
|
49
|
+
return contents
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
55
53
|
|
|
56
|
-
export { rollupStylesCSSImport }
|
|
54
|
+
export { rollupStylesCSSImport }
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { resolve, dirname, basename } from 'path'
|
|
2
|
-
import { readFileSync } from 'fs'
|
|
3
|
-
import { assetsRegExp } from '../../config.js'
|
|
1
|
+
import { resolve, dirname, basename } from 'path'
|
|
2
|
+
import { readFileSync } from 'fs'
|
|
3
|
+
import { assetsRegExp } from '../../config.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {Object} options
|
|
7
7
|
* @returns {Object}
|
|
8
8
|
*/
|
|
9
|
-
const rollupAssets =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
9
|
+
const rollupAssets = options => {
|
|
10
|
+
const { filter = assetsRegExp } = 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 contents = [
|
|
26
|
+
`const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
|
|
27
|
+
`const fileUrl = import.meta.ROLLUP_FILE_URL_${referenceId}.replace(reg, '');`,
|
|
28
|
+
'export default fileUrl;'
|
|
29
|
+
].join('\n')
|
|
30
|
+
return contents
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
export { rollupAssets }
|
|
36
|
+
export { rollupAssets }
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import { readdirSync } from 'fs'
|
|
1
|
+
import { join } from 'path'
|
|
2
|
+
import { readdirSync } from 'fs'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 获取指定目录下的所有 ts、js、jsx、tsx 文件
|
|
6
6
|
* @param dir 目录路径
|
|
7
7
|
* @returns 文件路径数组
|
|
8
8
|
*/
|
|
9
|
-
const getScriptFiles =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
26
|
|
|
26
|
-
export { getScriptFiles }
|
|
27
|
+
export { getScriptFiles }
|
package/lib/store.d.ts
CHANGED
|
@@ -1,88 +1,106 @@
|
|
|
1
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
|
|
2
|
-
import { RollupTypescriptOptions } from '@rollup/plugin-typescript'
|
|
3
|
-
import { RollupOptions, OutputOptions } from 'rollup'
|
|
4
|
-
import { Alias } from './typing.js'
|
|
1
|
+
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
|
|
2
|
+
import { RollupTypescriptOptions } from '@rollup/plugin-typescript'
|
|
3
|
+
import { RollupOptions, OutputOptions } from 'rollup'
|
|
4
|
+
import { Alias } from './typing.js'
|
|
5
5
|
|
|
6
|
-
type PluginsValue = (options: Options) => void
|
|
7
|
-
type PluginsCallBack =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
type PluginsValue = (options: Options) => void
|
|
7
|
+
type PluginsCallBack =
|
|
8
|
+
| PluginsValue
|
|
9
|
+
| {
|
|
10
|
+
load?: PluginsValue
|
|
11
|
+
build?: PluginsValue
|
|
12
|
+
}
|
|
13
|
+
type PluginsOptions = (options: Options) => PluginsCallBack | void
|
|
12
14
|
type Options = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 配置调整机及其回调插件
|
|
17
|
+
*/
|
|
18
|
+
plugins?: PluginsOptions[]
|
|
19
|
+
/**
|
|
20
|
+
* 别名
|
|
21
|
+
*/
|
|
22
|
+
alias?:
|
|
23
|
+
| {
|
|
21
24
|
/**
|
|
22
25
|
* 别名规则
|
|
23
26
|
*/
|
|
24
|
-
entries?: Alias[]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
entries?: Alias[]
|
|
28
|
+
}
|
|
29
|
+
| false
|
|
30
|
+
/**
|
|
31
|
+
* 静态资源识别
|
|
32
|
+
*/
|
|
33
|
+
assets?:
|
|
34
|
+
| {
|
|
30
35
|
/**
|
|
31
36
|
* 过滤得到指定格式的文件识别之为静态资源
|
|
32
37
|
*/
|
|
33
|
-
filter?: RegExp
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
filter?: RegExp
|
|
39
|
+
}
|
|
40
|
+
| false
|
|
41
|
+
styles?:
|
|
42
|
+
| {
|
|
36
43
|
/**
|
|
37
44
|
* 过滤得到指定格式的文件识别之为静态资源
|
|
38
45
|
*/
|
|
39
|
-
filter?: RegExp
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
filter?: RegExp
|
|
47
|
+
}
|
|
48
|
+
| false
|
|
49
|
+
/**
|
|
50
|
+
* 打包时配置
|
|
51
|
+
*/
|
|
52
|
+
build?:
|
|
53
|
+
| {
|
|
45
54
|
/**
|
|
46
55
|
* cjs文件处理
|
|
47
56
|
*/
|
|
48
|
-
commonjs?: RollupCommonJSOptions | false
|
|
57
|
+
commonjs?: RollupCommonJSOptions | false
|
|
49
58
|
/**
|
|
50
59
|
* ts配置
|
|
51
60
|
*/
|
|
52
|
-
typescript?: RollupTypescriptOptions | false
|
|
61
|
+
typescript?: RollupTypescriptOptions | false
|
|
53
62
|
/**
|
|
54
63
|
*
|
|
55
64
|
*/
|
|
56
|
-
RollupOptions?: RollupOptions
|
|
65
|
+
RollupOptions?: RollupOptions
|
|
57
66
|
/**
|
|
58
67
|
*
|
|
59
68
|
*/
|
|
60
69
|
OutputOptions?: OutputOptions & {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
/**
|
|
71
|
+
* 默认 src
|
|
72
|
+
*/
|
|
73
|
+
input?: string
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
| false
|
|
77
|
+
}
|
|
68
78
|
/**
|
|
69
79
|
*
|
|
70
80
|
*/
|
|
71
81
|
declare global {
|
|
72
|
-
|
|
82
|
+
var lvyConfig: Options
|
|
73
83
|
}
|
|
74
84
|
/**
|
|
75
85
|
*
|
|
76
86
|
*/
|
|
77
|
-
declare const initConfig: () => Promise<void
|
|
87
|
+
declare const initConfig: () => Promise<void>
|
|
78
88
|
/**
|
|
79
89
|
* @returns
|
|
80
90
|
*/
|
|
81
|
-
declare const getOptions: () => Options
|
|
91
|
+
declare const getOptions: () => Options
|
|
82
92
|
/**
|
|
83
93
|
* @param param0
|
|
84
94
|
* @returns
|
|
85
95
|
*/
|
|
86
|
-
declare const defineConfig: (optoins?: Options) => Options | undefined
|
|
96
|
+
declare const defineConfig: (optoins?: Options) => Options | undefined
|
|
87
97
|
|
|
88
|
-
export {
|
|
98
|
+
export {
|
|
99
|
+
type Options,
|
|
100
|
+
type PluginsCallBack,
|
|
101
|
+
type PluginsOptions,
|
|
102
|
+
type PluginsValue,
|
|
103
|
+
defineConfig,
|
|
104
|
+
getOptions,
|
|
105
|
+
initConfig
|
|
106
|
+
}
|
package/lib/store.js
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { existsSync } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
1
|
+
import { existsSync } from 'fs'
|
|
2
|
+
import { join } from 'path'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
const initConfig = async () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
8
|
+
if (!global.lvyConfig) global.lvyConfig = {}
|
|
9
|
+
const files = [
|
|
10
|
+
'lvy.config.ts',
|
|
11
|
+
'lvy.config.js',
|
|
12
|
+
'lvy.config.mjs',
|
|
13
|
+
'lvy.config.cjs',
|
|
14
|
+
'lvy.config.tsx'
|
|
15
|
+
]
|
|
16
|
+
let configDir = ''
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
if (existsSync(file)) {
|
|
19
|
+
configDir = file
|
|
20
|
+
break
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
}
|
|
23
|
+
if (configDir !== '') {
|
|
24
|
+
const v = await import(`file://${join(process.cwd(), configDir)}`)
|
|
25
|
+
if (v?.default) {
|
|
26
|
+
global.lvyConfig = v.default
|
|
29
27
|
}
|
|
30
|
-
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
31
30
|
/**
|
|
32
31
|
* @returns
|
|
33
32
|
*/
|
|
34
|
-
const getOptions = () => global.lvyConfig
|
|
33
|
+
const getOptions = () => global.lvyConfig
|
|
35
34
|
/**
|
|
36
35
|
* @param param0
|
|
37
36
|
* @returns
|
|
38
37
|
*/
|
|
39
|
-
const defineConfig =
|
|
38
|
+
const defineConfig = optoins => optoins
|
|
40
39
|
|
|
41
|
-
export { defineConfig, getOptions, initConfig }
|
|
40
|
+
export { defineConfig, getOptions, initConfig }
|
package/lib/typing.d.ts
CHANGED