Skip to content

Commit 3d00596

Browse files
committed
feat: 支持纯html(没有入口文件)的场景。
1 parent 3a52336 commit 3d00596

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

lib/builder.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* cpselvis <cpselvis@gmal.com>
99
*/
10+
const fs = require('fs');
1011
const path = require('path');
1112
const glob = require("glob");
1213
const webpack = require('webpack');
@@ -27,7 +28,7 @@ const projectRoot = Config.getPath();
2728

2829
// 最基础的配置
2930
const baseConfig = {
30-
entry: glob.sync(path.join(projectRoot, './src/pages/**/init.js')),
31+
entry: glob.sync(path.join(projectRoot, './src/pages/*')),
3132
module: {
3233
rules: []
3334
},
@@ -538,15 +539,21 @@ class Builder {
538539
.keys(entries)
539540
.map((index) => {
540541
const entry = entries[index];
541-
const match = entry.match(/\/pages\/(.*)\/init.js/);
542+
const entryFile = `${entry}/init.js`;
543+
// 支持 init.js 文件不是必须存在的场景,纯html
544+
const isEntryFileExists = fs.existsSync(entryFile);
545+
const match = entry.match(/\/pages\/(.*)/);
542546
const pageName = match && match[1];
547+
543548
let filename = '';
544549
if (htmlPrefix) {
545550
filename = htmlPrefix + '/';
546551
}
547552

548-
newEntry[pageName] = entry;
549-
553+
if (isEntryFileExists) {
554+
newEntry[pageName] = entryFile;
555+
}
556+
550557
htmlWebpackPlugins.push(new HtmlWebpackPlugin({
551558
inlineSource: inlineCSS
552559
? '\\.css$'
@@ -555,7 +562,7 @@ class Builder {
555562
filename: `${filename}${pageName}.html`,
556563
chunks: [pageName],
557564
assetsPrefix: `${assetsPrefix}/`,
558-
inject: inject,
565+
inject: inject && isEntryFileExists,
559566
minify: minifyHtml
560567
? {
561568
html5: true,

0 commit comments

Comments
 (0)