entry webpack. .
const fs = require('fs');
const path = require('path');
const getModulePath = module => path.resolve(__dirname, './relative/path/to/modules/directory', module);
const fileContent = fs.readFileSync('./your.json');
const entries = JSON.parse(fileContent).map(getModulePath);
module.exports = {
entry: {
bundle1: entries,
bundle2: [ './file1', './file2' ],
bundle3: './sindle/file',
all: [ ...entries, './file1', './file2', './sindle/file' ],
},
};
-
, webpack , .
, certan . .
const fs = require('fs');
const path = require('path');
const pathToCreatedFile = path.resolve(__dirname, './path/to/created/file');
const getModulePath = module => path.relative(pathToCreatedFile, path.resolve(
__dirname,
'./relative/path/to/modules/directory',
module,
));
const fileContent = fs.readFileSync('./path/to/your.json');
const entries = JSON.parse(fileContent)
.map(item => ({
name: item.slice(7),
relpath: getModulePath(item),
}));
const importsString = entries.map(({ name, relpath }) => `import * as ${name} from '${relpath}';`).join('\n');
const exportsString = `export {${entries.map(({name}) => name).join(',\n')}};`;
const content = [
entries.map(({ name, relpath }) => `import * as ${name} from '${relpath}';`).join('\n'),
`export {${entries.map(({name}) => name).join(',\n')}};`,
].join('\n');
fs.writeFileSync(pathToCreatedFile, content);
module.exports = {
entry: pathToCreatedFile,
};
. Object.values , .
aproach, exportString .
import * as name from ..., . , export * from ... export {default as name} from ... .