lvyjs 0.1.4 → 0.2.1

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 CHANGED
@@ -13,10 +13,12 @@ if (args.includes('build')) {
13
13
  const jsdir = relative(process.cwd(), jsFile)
14
14
  const argsx = args.filter(arg => arg !== 'build')
15
15
  let tsxDir = join(currentDirPath, '../../tsx/dist/cli.mjs')
16
- console.log('tsxDir', tsxDir)
17
16
  if (!existsSync(tsxDir)) {
18
17
  tsxDir = join(currentDirPath, '../node_modules/tsx/dist/cli.mjs')
19
18
  }
19
+ if (!existsSync(tsxDir)) {
20
+ tsxDir = join(process.cwd(), 'node_modules/tsx/dist/cli.mjs')
21
+ }
20
22
  const msg = fork(tsxDir, [jsdir, '--lvy-build', ...argsx], {
21
23
  stdio: 'inherit',
22
24
  env: Object.assign({}, process.env, {
@@ -38,10 +40,12 @@ if (args.includes('build')) {
38
40
  '--lvy-dev'
39
41
  ]
40
42
  let tsxDir = join(currentDirPath, '../../tsx/dist/cli.mjs')
41
- console.log('tsxDir', tsxDir)
42
43
  if (!existsSync(tsxDir)) {
43
44
  tsxDir = join(currentDirPath, '../node_modules/tsx/dist/cli.mjs')
44
45
  }
46
+ if (!existsSync(tsxDir)) {
47
+ tsxDir = join(process.cwd(), 'node_modules/tsx/dist/cli.mjs')
48
+ }
45
49
  const msg = fork(tsxDir, [...argv, ...argsx], {
46
50
  stdio: 'inherit',
47
51
  env: Object.assign({}, process.env, {
@@ -6,13 +6,13 @@ import { readdirSync } from 'fs';
6
6
  * @param dir 目录路径
7
7
  * @returns 文件路径数组
8
8
  */
9
- const getFiles = (dir) => {
9
+ const getScriptFiles = (dir) => {
10
10
  const results = [];
11
11
  const list = readdirSync(dir, { withFileTypes: true });
12
12
  list.forEach(item => {
13
13
  const fullPath = join(dir, item.name);
14
14
  if (item.isDirectory()) {
15
- results.push(...getFiles(fullPath));
15
+ results.push(...getScriptFiles(fullPath));
16
16
  }
17
17
  else if (item.isFile() &&
18
18
  /\.(ts|js|jsx|tsx)$/.test(item.name) &&
@@ -23,4 +23,4 @@ const getFiles = (dir) => {
23
23
  return results;
24
24
  };
25
25
 
26
- export { getFiles };
26
+ export { getScriptFiles };
@@ -4,7 +4,7 @@ import typescript from '@rollup/plugin-typescript';
4
4
  import commonjs from '@rollup/plugin-commonjs';
5
5
  import json from '@rollup/plugin-json';
6
6
  import styles from 'rollup-plugin-styles';
7
- import { getFiles } from './get-files.js';
7
+ import { getScriptFiles } from './get-files.js';
8
8
  import alias from '@rollup/plugin-alias';
9
9
  import { rollupStylesCSSImport } from '../plugins/loader-css.js';
10
10
  import { rollupAssets } from '../plugins/loader-files.js';
@@ -28,110 +28,116 @@ const onwarn = (warning, warn) => {
28
28
  * @param inputs
29
29
  * @param output
30
30
  */
31
- const buildJS = async (inputs, output) => {
31
+ const buildJS = async (inputs) => {
32
32
  if (!global.lvyConfig)
33
33
  global.lvyConfig = {};
34
34
  if (!global.lvyConfig.build)
35
35
  global.lvyConfig.build = {};
36
36
  // 插件
37
37
  const plugins = [];
38
- for (const key in global.lvyConfig.build) {
39
- if (typeof global.lvyConfig.build[key] == 'boolean') {
40
- continue;
41
- }
42
- if (key === 'alias' && !global.lvyConfig.build['@rollup/plugin-alias']) {
43
- plugins.push(alias(global.lvyConfig.build[key]));
44
- }
45
- else if (key === 'assets') {
46
- plugins.push(rollupAssets(global.lvyConfig.build[key]));
47
- }
48
- else if (key === 'styles') {
49
- plugins.push(styles({
50
- mode: ['inject', () => '']
51
- }));
52
- plugins.push(rollupStylesCSSImport(global.lvyConfig.build[key]));
53
- }
54
- else if (key === 'commonjs' && !global.lvyConfig.build['@rollup/plugin-commonjs']) {
55
- plugins.push(commonjs(global.lvyConfig.build[key]));
56
- }
57
- else if (key === 'json' && !global.lvyConfig.build['@rollup/plugin-json']) {
58
- plugins.push(json(global.lvyConfig.build[key]));
59
- }
60
- else if (key === 'typescript' && !global.lvyConfig.build['@rollup/plugin-typescript']) {
61
- plugins.push(typescript(global.lvyConfig.build[key]));
62
- }
63
- else if (key === 'plugins') {
64
- if (Array.isArray(global.lvyConfig.build[key])) {
65
- for (const plugin of global.lvyConfig.build[key]) {
66
- plugins.push(plugin);
67
- }
68
- }
69
- }
70
- else {
71
- const plugin = (await import(key)).default;
72
- plugins.push(plugin(global.lvyConfig.build[key]));
73
- }
38
+ if (global.lvyConfig?.alias) {
39
+ plugins.push(alias(global.lvyConfig.alias));
74
40
  }
75
- // 如果不存在这些配置
76
- const keys = ['assets', 'styles', 'commonjs', 'json', 'typescript'];
77
- for (const key of keys) {
78
- // 如果是布尔值
79
- if (typeof global.lvyConfig.build[key] == 'boolean') {
80
- continue;
81
- }
82
- // 存在这些配置
83
- if (global.lvyConfig.build[key]) {
84
- continue;
85
- }
41
+ if (global.lvyConfig.assets) {
42
+ plugins.push(rollupAssets(global.lvyConfig.assets));
43
+ }
44
+ else {
45
+ plugins.push(rollupAssets());
46
+ }
47
+ if (typeof global.lvyConfig.build != 'boolean') {
86
48
  //
87
- if (key == 'assets') {
88
- plugins.push(rollupAssets());
89
- }
90
- else if (key == 'styles') {
91
- plugins.push(styles({
92
- mode: ['inject', () => '']
93
- }));
94
- plugins.push(rollupStylesCSSImport());
95
- }
96
- else if (key === 'commonjs') {
97
- plugins.push(commonjs());
98
- }
99
- else if (key === 'json') {
100
- plugins.push(json());
101
- }
102
- else if (key === 'typescript') {
103
- plugins.push(typescript());
49
+ for (const key in global.lvyConfig.build) {
50
+ if (typeof global.lvyConfig.build[key] == 'boolean') {
51
+ continue;
52
+ }
53
+ if (key === 'styles') {
54
+ plugins.push(styles({
55
+ mode: ['inject', () => '']
56
+ }));
57
+ plugins.push(rollupStylesCSSImport(global.lvyConfig.build[key]));
58
+ }
59
+ else if (key === 'commonjs' && !global.lvyConfig.build['@rollup/plugin-commonjs']) {
60
+ plugins.push(commonjs(global.lvyConfig.build[key]));
61
+ }
62
+ else if (key === 'json' && !global.lvyConfig.build['@rollup/plugin-json']) {
63
+ plugins.push(json(global.lvyConfig.build[key]));
64
+ }
65
+ else if (key === 'typescript' && !global.lvyConfig.build['@rollup/plugin-typescript']) {
66
+ plugins.push(typescript(global.lvyConfig.build[key]));
67
+ }
68
+ else if (key === 'plugins') {
69
+ if (Array.isArray(global.lvyConfig.build[key])) {
70
+ for (const plugin of global.lvyConfig.build[key]) {
71
+ plugins.push(plugin);
72
+ }
73
+ }
74
+ }
75
+ else {
76
+ const plugin = (await import(key)).default;
77
+ plugins.push(plugin(global.lvyConfig.build[key]));
78
+ }
104
79
  }
105
- else if (key === 'plugins') {
106
- plugins.push(alias());
80
+ // 如果不存在这些配置
81
+ const keys = ['styles', 'commonjs', 'json', 'typescript'];
82
+ for (const key of keys) {
83
+ // 如果是布尔值
84
+ if (typeof global.lvyConfig.build[key] == 'boolean') {
85
+ continue;
86
+ }
87
+ // 存在这些配置
88
+ if (global.lvyConfig.build[key]) {
89
+ continue;
90
+ }
91
+ //
92
+ if (key == 'styles') {
93
+ plugins.push(styles({
94
+ mode: ['inject', () => '']
95
+ }));
96
+ plugins.push(rollupStylesCSSImport());
97
+ }
98
+ else if (key === 'commonjs') {
99
+ plugins.push(commonjs());
100
+ }
101
+ else if (key === 'json') {
102
+ plugins.push(json());
103
+ }
104
+ else if (key === 'typescript') {
105
+ plugins.push(typescript());
106
+ }
107
107
  }
108
108
  }
109
109
  // rollup 配置
110
- const Options = global.lvyConfig.build?.rollupOptions ?? {};
111
- // rollup 配置
112
- const rollupOptions = {
113
- input: inputs,
114
- plugins: plugins,
115
- onwarn: onwarn,
116
- ...Options
117
- };
110
+ const rollupOptions = global.lvyConfig?.rollupOptions ?? {};
111
+ const rollupPlugins = global.lvyConfig?.rollupPlugins ?? [];
118
112
  // build
119
- const bundle = await rollup(rollupOptions);
113
+ const bundle = await rollup({
114
+ input: inputs,
115
+ plugins: [...plugins, ...rollupPlugins],
116
+ onwarn: onwarn
117
+ });
120
118
  // 写入输出文件
121
119
  await bundle.write({
122
- dir: output,
120
+ dir: 'lib',
123
121
  format: 'es',
124
122
  sourcemap: false,
125
- preserveModules: true
123
+ preserveModules: true,
124
+ assetFileNames: 'assets/[name]-[hash][extname]',
125
+ ...rollupOptions
126
126
  });
127
127
  };
128
128
  /**
129
129
  *
130
130
  * @param script
131
131
  */
132
- async function buildAndRun(input, output) {
133
- const inputFiles = getFiles(join(process.cwd(), input));
134
- await buildJS(inputFiles, output);
132
+ async function buildAndRun() {
133
+ // rollup 配置
134
+ let inputDir = 'src';
135
+ if (global.lvyConfig?.rollupOptions?.input) {
136
+ inputDir = global.lvyConfig.rollupOptions.input;
137
+ delete global.lvyConfig.rollupOptions['input'];
138
+ }
139
+ const inputFiles = getScriptFiles(join(process.cwd(), inputDir));
140
+ await buildJS(inputFiles);
135
141
  }
136
142
 
137
143
  export { buildAndRun, buildJS };
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { defineConfig, initConfig } from './loader/store.js';
1
+ export { defineConfig, initConfig, usePlugin } from './loader/store.js';
package/lib/index.js CHANGED
@@ -1,40 +1,32 @@
1
1
  import { buildAndRun } from './build/rullup.js';
2
2
  import { initConfig } from './loader/store.js';
3
- export { defineConfig } from './loader/store.js';
3
+ export { defineConfig, usePlugin } from './loader/store.js';
4
4
 
5
5
  /**
6
6
  * @param input
7
7
  */
8
8
  const onDev = async () => {
9
- // 修改config
10
- for (const plugin of global.lvyConfig.plugins) {
11
- if (plugin?.config) {
12
- const cfg = await plugin.config(global.lvyConfig);
13
- for (const key in cfg) {
14
- // 不能覆盖plugins
15
- if (cfg[key] != 'plugins') {
16
- // 覆盖
17
- global.lvyConfig[key] = cfg[key];
18
- }
9
+ const apps = [];
10
+ if (Array.isArray(global.lvyConfig?.plugins)) {
11
+ // 修改config
12
+ for (const plugin of global.lvyConfig.plugins) {
13
+ if (!plugin) {
14
+ continue;
19
15
  }
16
+ apps.push(plugin(global.lvyConfig));
20
17
  }
21
18
  }
22
19
  // 执行loader
23
20
  await import('./main.js');
24
- // 执行 useApp
25
- for (const plugin of global.lvyConfig.plugins) {
26
- if (plugin?.useApp)
27
- await plugin.useApp();
21
+ //
22
+ for (const app of apps) {
23
+ if (!app) {
24
+ continue;
25
+ }
26
+ if (typeof app == 'function')
27
+ app(global.lvyConfig);
28
28
  }
29
29
  };
30
- /**
31
- *
32
- * @param input
33
- * @param ouput
34
- */
35
- const onBuild = () => {
36
- buildAndRun('src', 'lib');
37
- };
38
30
  const main = async () => {
39
31
  if (process.argv.includes('--lvy-dev')) {
40
32
  await initConfig();
@@ -42,7 +34,7 @@ const main = async () => {
42
34
  }
43
35
  else if (process.argv.includes('--lvy-build')) {
44
36
  await initConfig();
45
- onBuild();
37
+ buildAndRun();
46
38
  }
47
39
  };
48
40
  main();
@@ -0,0 +1,4 @@
1
+ const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/;
2
+ const cssReg = /\.(css|scss)$/;
3
+
4
+ export { assetsReg, cssReg };
@@ -1,17 +1,17 @@
1
1
  import esbuild from 'esbuild';
2
- import { esBuildAsstes, esBuildCSS } from './plugins.js';
2
+ import { esBuildAlias, esBuildAsstes, esBuildCSS } from './plugins.js';
3
3
 
4
4
  // 插件
5
5
  const plugins = [];
6
6
  /**
7
7
  *
8
8
  */
9
- const initPlugins = async () => {
10
- if (typeof global.lvyConfig?.esbuild?.assets != 'boolean') {
11
- plugins.push(esBuildAsstes(global.lvyConfig.esbuild.assets));
9
+ const initPlugins = () => {
10
+ if (global.lvyConfig?.assets) {
11
+ plugins.push(esBuildAsstes(global.lvyConfig.assets));
12
12
  }
13
13
  if (typeof global.lvyConfig?.esbuild?.styles != 'boolean') {
14
- plugins.push(esBuildCSS(global.lvyConfig.esbuild.styles));
14
+ plugins.push(esBuildCSS(global.lvyConfig.esbuild?.styles));
15
15
  }
16
16
  };
17
17
  /**
@@ -25,13 +25,16 @@ const ESBuild = async (input) => {
25
25
  global.lvyConfig = {};
26
26
  if (!global.lvyConfig.esbuild)
27
27
  global.lvyConfig.esbuild = {};
28
+ // alias
29
+ if (global.lvyConfig.alias)
30
+ esBuildAlias(global.lvyConfig.alias);
28
31
  // 没有插件时,检查是否有可用插件。
29
32
  if (plugins.length === 0) {
30
33
  // init plugisn
31
34
  await initPlugins();
32
35
  }
33
36
  //
34
- const options = global.lvyConfig.esbuild?.options || {};
37
+ const options = global.lvyConfig?.esBuildOptions || {};
35
38
  // 构建
36
39
  const result = await esbuild.build({
37
40
  // 入口文件
@@ -49,6 +52,9 @@ const ESBuild = async (input) => {
49
52
  external: ['*'],
50
53
  ...options
51
54
  });
55
+ if (!result.outputFiles) {
56
+ return '';
57
+ }
52
58
  // 返回结果
53
59
  return result.outputFiles.map(file => new TextDecoder().decode(file.contents)).join('\n');
54
60
  };
@@ -1,10 +1,6 @@
1
- type ESBuildAsstesOptions = {
2
- filter?: RegExp;
3
- namespace?: string;
4
- };
5
1
  type ESBuildCSSOptions = {
6
2
  filter?: RegExp;
7
3
  namespace?: string;
8
4
  };
9
5
 
10
- export type { ESBuildAsstesOptions, ESBuildCSSOptions };
6
+ export type { ESBuildCSSOptions };
@@ -1,32 +1,8 @@
1
1
  import { resolve, relative, dirname, join } from 'path';
2
- import { existsSync, readFileSync } from 'fs';
3
2
  import { spawn } from 'child_process';
4
3
  import crypto from 'node:crypto';
5
- import JSON5 from 'json5';
4
+ import { assetsReg, cssReg } from './config.js';
6
5
 
7
- let tsconfig = null;
8
- let aliases = {};
9
- const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/;
10
- const cssReg = /\.(css|scss)$/;
11
- // 初始化函数,读取并解析 tsconfig.json 文件
12
- const init = () => {
13
- try {
14
- const tsconfigPath = resolve(process.cwd(), 'tsconfig.json');
15
- if (existsSync(tsconfigPath)) {
16
- const tsconfigContent = readFileSync(tsconfigPath, 'utf-8');
17
- tsconfig = JSON5.parse(tsconfigContent);
18
- aliases = tsconfig.compilerOptions?.paths || {};
19
- }
20
- else {
21
- tsconfig = 'error';
22
- }
23
- }
24
- catch {
25
- tsconfig = 'error';
26
- }
27
- };
28
- // 初始化配置
29
- init();
30
6
  /**
31
7
  *
32
8
  * @param input
@@ -79,14 +55,28 @@ const getHash = (str) => {
79
55
  hash.update(str);
80
56
  return hash.digest('hex');
81
57
  };
58
+ let entries = null;
59
+ const esBuildAlias = (alias) => {
60
+ if (!entries) {
61
+ entries = alias?.entries ?? [];
62
+ }
63
+ };
82
64
  const handleAsstesFile = (url) => {
83
- for (const alias in aliases) {
84
- const aliasPattern = alias.replace('/*', '');
85
- if (url.startsWith(aliasPattern)) {
86
- const aliasPaths = aliases[alias];
87
- for (const aliasPath of aliasPaths) {
88
- const fileUrl = join(process.cwd(), aliasPath.replace('/*', ''), url.replace(aliasPattern, ''));
89
- return `export default "${convertPath(fileUrl)}";`;
65
+ if (entries) {
66
+ for (const { find, replacement } of entries) {
67
+ if (typeof find === 'string') {
68
+ // 使用 startsWith 处理字符串类型
69
+ if (url.startsWith(find)) {
70
+ const fileUrl = join(replacement, url.replace(find, ''));
71
+ return `export default "${convertPath(fileUrl)}";`;
72
+ }
73
+ }
74
+ else if (find instanceof RegExp) {
75
+ // 使用 test 方法处理正则表达式类型
76
+ if (find.test(url)) {
77
+ const fileUrl = join(replacement, url.replace(find, ''));
78
+ return `export default "${convertPath(fileUrl)}";`;
79
+ }
90
80
  }
91
81
  }
92
82
  }
@@ -109,17 +99,26 @@ const handleCSS = (fileUrl) => {
109
99
  /**
110
100
  * 处理路径别名的加载
111
101
  * @param {string} url URL
112
- * @returns {object|null} 加载结果
102
+ * @returns {string|null} 加载结果
113
103
  */
114
104
  const handleCSSPath = (url) => {
115
- for (const alias in aliases) {
116
- const aliasPattern = alias.replace('/*', '');
117
- if (url.startsWith(aliasPattern)) {
118
- const aliasPaths = aliases[alias];
119
- for (const aliasPath of aliasPaths) {
120
- const fileUrl = join(process.cwd(), aliasPath.replace('/*', ''), url.replace(aliasPattern, ''));
121
- const outputDir = handleCSS(fileUrl);
122
- return `export default "${convertPath(outputDir)}";`;
105
+ if (entries) {
106
+ for (const { find, replacement } of entries) {
107
+ if (typeof find === 'string') {
108
+ // 使用 startsWith 处理字符串类型
109
+ if (url.startsWith(find)) {
110
+ const fileUrl = join(replacement, url.replace(find, ''));
111
+ const outputDir = handleCSS(fileUrl);
112
+ return `export default "${convertPath(outputDir)}";`;
113
+ }
114
+ }
115
+ else if (find instanceof RegExp) {
116
+ // 使用 test 方法处理正则表达式类型
117
+ if (find.test(url)) {
118
+ const fileUrl = join(replacement, url.replace(find, ''));
119
+ const outputDir = handleCSS(fileUrl);
120
+ return `export default "${convertPath(outputDir)}";`;
121
+ }
123
122
  }
124
123
  }
125
124
  }
@@ -129,10 +128,10 @@ const handleCSSPath = (url) => {
129
128
  *
130
129
  * @param param0
131
130
  */
132
- const esBuildAsstes = (optoins = {}) => {
131
+ const esBuildAsstes = (optoins) => {
133
132
  // 默认配置
134
133
  const filter = optoins?.filter ?? assetsReg;
135
- const namespace = optoins?.namespace ?? 'assets';
134
+ const namespace = 'assets';
136
135
  // 返回插件
137
136
  return {
138
137
  name: 'assets-loader',
@@ -173,7 +172,7 @@ const esBuildAsstes = (optoins = {}) => {
173
172
  * @param param0
174
173
  * @returns
175
174
  */
176
- const esBuildCSS = (optoins = {}) => {
175
+ const esBuildCSS = (optoins) => {
177
176
  const filter = optoins?.filter || cssReg;
178
177
  const namespace = optoins?.namespace || 'css';
179
178
  // 返回插件
@@ -215,4 +214,4 @@ const esBuildCSS = (optoins = {}) => {
215
214
  };
216
215
  };
217
216
 
218
- export { esBuildAsstes, esBuildCSS };
217
+ export { esBuildAlias, esBuildAsstes, esBuildCSS };
@@ -1,64 +1,68 @@
1
- import { RollupAliasOptions } from '@rollup/plugin-alias';
2
- import { RollupOptions } from 'rollup';
1
+ import { Alias } from '@rollup/plugin-alias';
3
2
  import { RollupStylesCSSImportOptions } from '../plugins/loader-css.js';
4
3
  import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
5
4
  import { RollupJsonOptions } from '@rollup/plugin-json';
6
5
  import { RollupTypescriptOptions } from '@rollup/plugin-typescript';
7
6
  import { SameShape, BuildOptions } from 'esbuild';
8
- import { RollupAssetsOptions } from '../plugins/loader-files.js';
9
- import { ESBuildAsstesOptions, ESBuildCSSOptions } from './plugins.js';
7
+ import { ESBuildCSSOptions } from './plugins.js';
8
+ import { RollupBuild } from 'rollup';
10
9
 
10
+ type RollupBuildOptions = Parameters<RollupBuild['write']>['0'];
11
11
  type Options = {
12
12
  /**
13
13
  * 配置调整机及其回调插件
14
14
  */
15
- plugins?: {
16
- /**
17
- * 应用名
18
- */
19
- name: string;
15
+ plugins?: ((options: Options) => ((options: Options) => void) | void | undefined | null)[];
16
+ /**
17
+ * 别名
18
+ */
19
+ alias?: {
20
20
  /**
21
- * ⚠️直接optoins进行调整
22
- * @param options
23
- * @returns
21
+ * 别名规则
24
22
  */
25
- config?: (options: Options) => Options;
23
+ entries?: Alias[];
24
+ };
25
+ /**
26
+ * 静态资源识别
27
+ */
28
+ assets?: {
26
29
  /**
27
- * 执行
30
+ * 过滤得到指定格式的文件识别之为静态资源
28
31
  */
29
- useApp?: () => void;
30
- }[];
32
+ filter?: RegExp;
33
+ };
34
+ /**
35
+ *
36
+ */
37
+ esBuildOptions?: SameShape<BuildOptions, BuildOptions>;
31
38
  /**
32
39
  * 运行时配置
33
40
  */
34
41
  esbuild?: {
35
42
  [key: string]: any;
36
- /**
37
- * 资源
38
- */
39
- assets?: ESBuildAsstesOptions | false;
40
43
  /**
41
44
  * 样式处理
42
45
  */
43
46
  styles?: ESBuildCSSOptions | false;
47
+ };
48
+ /**
49
+ * ⚠️ RollupBuild['write'] 配置
50
+ */
51
+ rollupOptions?: RollupBuildOptions & {
44
52
  /**
45
- * ⚠️ 直接覆盖esbuild配置
53
+ * 默认 src
46
54
  */
47
- options?: SameShape<BuildOptions, BuildOptions>;
55
+ input?: string;
48
56
  };
57
+ /**
58
+ *使用插件
59
+ */
60
+ rollupPlugins?: any[];
49
61
  /**
50
62
  * 打包时配置
51
63
  */
52
64
  build?: {
53
65
  [key: string]: any;
54
- /**
55
- * 别名
56
- */
57
- alias?: RollupAliasOptions | false;
58
- /**
59
- * 文件过滤
60
- */
61
- assets?: RollupAssetsOptions | false;
62
66
  /**
63
67
  * 样式处理配置
64
68
  */
@@ -75,18 +79,14 @@ type Options = {
75
79
  * ts配置
76
80
  */
77
81
  typescript?: RollupTypescriptOptions | false;
78
- /**
79
- *
80
- */
81
- plugins?: any[];
82
- /**
83
- * ⚠️ 直接覆盖build配置
84
- */
85
- rollupOptions?: {
86
- input?: string | string[];
87
- } & RollupOptions;
88
- };
82
+ } | false;
89
83
  };
84
+ /**
85
+ *
86
+ * @param options
87
+ * @returns
88
+ */
89
+ declare const usePlugin: (load: (options: Options) => ((options: Options) => void) | void | undefined | null) => (options: Options) => ((options: Options) => void) | void | undefined | null;
90
90
  /**
91
91
  *
92
92
  */
@@ -101,6 +101,6 @@ declare const initConfig: () => Promise<void>;
101
101
  * @param param0
102
102
  * @returns
103
103
  */
104
- declare const defineConfig: (optoins?: Options) => Options;
104
+ declare const defineConfig: (optoins?: Options) => Options | undefined;
105
105
 
106
- export { type Options, defineConfig, initConfig };
106
+ export { type Options, defineConfig, initConfig, usePlugin };
@@ -1,6 +1,12 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { join } from 'path';
3
3
 
4
+ /**
5
+ *
6
+ * @param options
7
+ * @returns
8
+ */
9
+ const usePlugin = (load) => load;
4
10
  /**
5
11
  *
6
12
  */
@@ -34,4 +40,4 @@ const initConfig = async () => {
34
40
  */
35
41
  const defineConfig = (optoins) => optoins;
36
42
 
37
- export { defineConfig, initConfig };
43
+ export { defineConfig, initConfig, usePlugin };
@@ -0,0 +1,4 @@
1
+ const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/;
2
+ const cssReg = /\.(css|scss)$/;
3
+
4
+ export { assetsReg, cssReg };
@@ -1,16 +1,18 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
2
  import { resolve, dirname, basename } from 'node:path';
3
+ import { cssReg } from './config.js';
3
4
 
4
5
  /**
5
6
  *
6
7
  * @returns
7
8
  */
8
- const rollupStylesCSSImport = ({ include = /\.(css|scss)$/i } = {}) => {
9
+ const rollupStylesCSSImport = (options) => {
10
+ const { include = cssReg } = options ?? {};
9
11
  const filter = createFilter(include, null);
10
12
  return {
11
13
  name: 'c-css',
12
14
  resolveId(source, importer) {
13
- if (filter(source)) {
15
+ if (filter(source) && importer) {
14
16
  return resolve(dirname(importer), source);
15
17
  }
16
18
  },
@@ -1,5 +1,12 @@
1
+ import { InputPluginOption } from 'rollup';
2
+
1
3
  type RollupAssetsOptions = {
2
4
  filter?: RegExp;
3
5
  };
6
+ /**
7
+ * @param {Object} options
8
+ * @returns {Object}
9
+ */
10
+ declare const rollupAssets: (options?: RollupAssetsOptions) => InputPluginOption;
4
11
 
5
- export type { RollupAssetsOptions };
12
+ export { type RollupAssetsOptions, rollupAssets };
@@ -1,15 +1,17 @@
1
1
  import { resolve, dirname, basename } from 'path';
2
2
  import { readFileSync } from 'fs';
3
+ import { assetsReg } from './config.js';
3
4
 
4
5
  /**
5
6
  * @param {Object} options
6
7
  * @returns {Object}
7
8
  */
8
- const rollupAssets = ({ filter = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/ } = {}) => {
9
+ const rollupAssets = (options) => {
10
+ const { filter = assetsReg } = options ?? {};
9
11
  return {
10
12
  name: 'rollup-node-files',
11
13
  resolveId(source, importer) {
12
- if (filter.test(source)) {
14
+ if (filter.test(source) && importer) {
13
15
  return resolve(dirname(importer), source);
14
16
  }
15
17
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
package/tsconfig.json CHANGED
@@ -1,25 +1,31 @@
1
1
  {
2
2
  "compilerOptions": {
3
- // model
3
+ /* model */
4
4
  "target": "ESNext",
5
5
  "module": "ESNext",
6
- "allowJs": false,
7
6
  "esModuleInterop": true,
7
+ /* json */
8
8
  "resolveJsonModule": true,
9
- // jsx
9
+ /* Bundler mode */
10
10
  "jsx": "react",
11
11
  "moduleResolution": "bundler",
12
12
  "allowImportingTsExtensions": true,
13
+ "moduleDetection": "force",
13
14
  "noEmit": true,
14
- // version
15
+ "skipLibCheck": true,
16
+ /* version */
15
17
  "ignoreDeprecations": "5.0",
16
- // strict
18
+ /* strict */
19
+ "allowJs": false,
17
20
  "noImplicitAny": false,
18
21
  "useDefineForClassFields": true,
19
22
  "isolatedModules": true,
23
+ "forceConsistentCasingInFileNames": true,
24
+ /* Linting */
25
+ "strict": true,
20
26
  "noUnusedLocals": true,
21
27
  "noUnusedParameters": true,
22
28
  "noFallthroughCasesInSwitch": true,
23
- "forceConsistentCasingInFileNames": true
29
+ "noUncheckedSideEffectImports": true
24
30
  }
25
31
  }