77 *
88 * cpselvis <cpselvis@gmal.com>
99 */
10+ const fs = require ( 'fs' ) ;
1011const path = require ( 'path' ) ;
1112const glob = require ( "glob" ) ;
1213const webpack = require ( 'webpack' ) ;
@@ -27,7 +28,7 @@ const projectRoot = Config.getPath();
2728
2829// 最基础的配置
2930const 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 ( / \/ p a g e s \/ ( .* ) \/ i n i t .j s / ) ;
542+ const entryFile = `${ entry } /init.js` ;
543+ // 支持 init.js 文件不是必须存在的场景,纯html
544+ const isEntryFileExists = fs . existsSync ( entryFile ) ;
545+ const match = entry . match ( / \/ p a g e s \/ ( .* ) / ) ;
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