@wjunt/webpack-config
Version:
Presets of webpack config
28 lines (27 loc) • 980 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const glob = require("glob");
const DEFAULTS = {
context: 'src',
pattern: 'pages/**/index.{[jt]s?(|x),vue}',
exclude: /\/(common|module|component|style)s?\//,
entryName: (name) => name
.replace(/^pages\//, '')
.replace(/\/index$/, ''),
};
function pages(options = {}) {
const { context = DEFAULTS.context, pattern = DEFAULTS.pattern, exclude = DEFAULTS.exclude, entryName = DEFAULTS.entryName, } = options;
const cwd = path.resolve(context);
const pages = glob.sync(pattern, { cwd }).filter((page) => !exclude.test(page));
const entry = pages.reduce((entry, name) => {
const extension = path.extname(name);
entry[entryName(name.slice(0, -extension.length), extension)] = path.join(cwd, name);
return entry;
}, {});
return {
context: cwd,
entry,
};
}
exports.pages = pages;