feat: +pagespy; build: +rollup
parent
5c32c721ae
commit
524b1e4770
@ -0,0 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
||||
const commonjs = require('@rollup/plugin-commonjs');
|
||||
const babel = require('@rollup/plugin-babel');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// each file in utils
|
||||
const utilsDir = path.join(__dirname, 'src', 'utils');
|
||||
const utilsFiles = fs.readdirSync(utilsDir).filter((file) => file.endsWith('.js') && file !== 'index.js');
|
||||
|
||||
const srcDir = path.join(__dirname, 'src');
|
||||
const hasIndexFiles = [];
|
||||
const srcItems = fs.readdirSync(srcDir);
|
||||
srcItems.forEach((item) => {
|
||||
const itemPath = path.join(srcDir, item);
|
||||
if (fs.statSync(itemPath).isDirectory()) {
|
||||
const _Files = fs.readdirSync(itemPath).filter((file) => file.endsWith('.js') && file === 'index.js');
|
||||
if (_Files.length > 0) {
|
||||
hasIndexFiles.push(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
// console.log('🍕🍕🍕', utilsFiles);
|
||||
// console.log('🍕🍕', hasIndexFiles);
|
||||
const indexEntries = [];
|
||||
hasIndexFiles.forEach(subDir => {
|
||||
indexEntries.push(...generateEntries(['index.js'], subDir));
|
||||
});
|
||||
// src/index.js
|
||||
indexEntries.push(...generateEntries(['index.js']));
|
||||
// console.log('🍕', indexEntries);
|
||||
// return;
|
||||
|
||||
function generateEntries(files, parentDir) {
|
||||
// Create entries with both ESM and CJS outputs
|
||||
const _Entries = files.flatMap((file) => {
|
||||
const moduleName = path.basename(file, '.js');
|
||||
// console.log('🍕', file, moduleName);
|
||||
|
||||
return [
|
||||
// ESM output
|
||||
{
|
||||
input: parentDir ? `src/${parentDir}/${file}` : `src/${file}`,
|
||||
output: {
|
||||
file: parentDir ? `build/esm/${parentDir}/${moduleName}.js` : `build/esm/${moduleName}.js`,
|
||||
format: 'es',
|
||||
exports: 'named',
|
||||
},
|
||||
external: [],
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
preferBuiltins: false,
|
||||
}),
|
||||
commonjs(),
|
||||
babel({
|
||||
babelHelpers: 'bundled',
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules: false,
|
||||
targets: '> 0.25%, not dead',
|
||||
exclude: ['transform-parameters'],
|
||||
},
|
||||
],
|
||||
],
|
||||
exclude: 'node_modules/**',
|
||||
}),
|
||||
],
|
||||
},
|
||||
// CJS output
|
||||
{
|
||||
input: parentDir ? `src/${parentDir}/${file}` : `src/${file}`,
|
||||
output: {
|
||||
file: parentDir ? `build/cjs/${parentDir}/${moduleName}.js` : `build/cjs/${moduleName}.js`,
|
||||
format: 'cjs',
|
||||
exports: 'named',
|
||||
},
|
||||
external: [],
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
preferBuiltins: false,
|
||||
}),
|
||||
commonjs(),
|
||||
babel({
|
||||
babelHelpers: 'bundled',
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules: false,
|
||||
targets: 'node 14',
|
||||
},
|
||||
],
|
||||
],
|
||||
exclude: 'node_modules/**',
|
||||
}),
|
||||
],
|
||||
},
|
||||
];
|
||||
});
|
||||
return _Entries;
|
||||
}
|
||||
|
||||
module.exports = [
|
||||
// ...utilsEntries
|
||||
...generateEntries(utilsFiles, 'utils'),
|
||||
...indexEntries,
|
||||
];
|
||||
@ -1,3 +1,4 @@
|
||||
// Auto Generated index.js
|
||||
export * as commons from './commons.js';
|
||||
export * as pagespy from './pagespy.js';
|
||||
export * as request from './request.js';
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
卷 软件 的文件夹 PATH 列表
|
||||
卷序列号为 C9C1-727D
|
||||
D:.
|
||||
│ .babelrc
|
||||
│ .gitignore
|
||||
│ .npmignore
|
||||
│ package-lock.json
|
||||
│ package.json
|
||||
│ README.MD
|
||||
│
|
||||
├─build
|
||||
│ ├─cjs
|
||||
│ │ │ index.js
|
||||
│ │ │
|
||||
│ │ ├─hooks
|
||||
│ │ │ index.js
|
||||
│ │ │ useHTLanguageSets.js
|
||||
│ │ │
|
||||
│ │ └─utils
|
||||
│ │ commons.js
|
||||
│ │ index.js
|
||||
│ │ request.js
|
||||
│ │
|
||||
│ └─esm
|
||||
│ │ index.js
|
||||
│ │
|
||||
│ ├─hooks
|
||||
│ │ index.js
|
||||
│ │ useHTLanguageSets.js
|
||||
│ │
|
||||
│ └─utils
|
||||
│ commons.js
|
||||
│ index.js
|
||||
│ request.js
|
||||
│
|
||||
├─dist
|
||||
│ haina-npm-0.1.0.tgz
|
||||
│ hooks-0.1.0.tgz
|
||||
│ structure.txt
|
||||
│ utils-0.1.0.tgz
|
||||
│ utils-commons-0.1.0.tgz
|
||||
│ utils-request-0.1.0.tgz
|
||||
│
|
||||
├─scripts
|
||||
│ generate-indexes.js
|
||||
│ pack-modules.js
|
||||
│
|
||||
└─src
|
||||
│ index.js
|
||||
│
|
||||
├─hooks
|
||||
│ index.js
|
||||
│ useHTLanguageSets.js
|
||||
│
|
||||
└─utils
|
||||
commons.js
|
||||
index.js
|
||||
request.js
|
||||
|
||||
Loading…
Reference in New Issue