@@ -4,6 +4,7 @@ import WebpackChain from 'webpack-chain';
44import * as path from 'path' ;
55import babelCompiler from 'build-plugin-component/src/compiler/babel' ;
66import openBrowser from 'react-dev-utils/openBrowser' ;
7+ import { existsSync } from 'fs-extra' ;
78import baseConfig from './baseConfig' ;
89import devConfig from './devConfig' ;
910import builtinConfig from './builtinConfig' ;
@@ -19,8 +20,13 @@ interface IOpitons {
1920}
2021
2122const plugin : IPlugin = ( { context, registerTask, onGetWebpackConfig, onHook, log } , options ) => {
22- const { type, inject, openUrl, generateMeta = false } = options as unknown as IOpitons ;
23+ const { type, inject, openUrl, generateMeta = true } = options as unknown as IOpitons ;
2324 const { command, rootDir, userConfig, pkg } = context ;
25+ const mainFilePrefix = path . join ( rootDir , 'src' , ( pkg . main as string ) . replace ( / l i b \/ ( .* ) .j s / , "$1" ) ) ;
26+ let mainFile = `${ mainFilePrefix } .tsx` ;
27+ if ( ! existsSync ( mainFile ) ) {
28+ mainFile = `${ mainFilePrefix } .jsx` ;
29+ }
2430 if ( command === 'start' ) {
2531 if ( type !== 'component' ) {
2632 const webpackConfig = getWebpackConfig ( 'development' ) as WebpackChain ;
@@ -30,6 +36,9 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
3036 baseConfig ( config , {
3137 rootDir,
3238 type,
39+ pkg,
40+ mainFile,
41+ generateMeta,
3342 entry : {
3443 index : path . join ( __dirname , `./entry/${ type } .js` ) ,
3544 preview : path . join ( __dirname , './entry/preview.js' ) ,
@@ -50,6 +59,7 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
5059 baseConfig ( config , {
5160 rootDir,
5261 type,
62+ mainFile,
5363 entry : {
5464 component : path . join ( __dirname , './builtIn/component.js' ) ,
5565 }
@@ -81,7 +91,6 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
8191 onHook ( 'before.build.load' , ( ) => {
8292 const babelPlugins = [ ] ;
8393 if ( type === 'plugin' && generateMeta && pkg . lcMeta ) {
84- const mainFile = path . join ( rootDir , 'src' , `${ ( pkg . main as string ) . replace ( / l i b \/ ( .* ) .j s / , "$1" ) } .tsx` ) ;
8594 babelPlugins . push ( [ require . resolve ( './babelPluginMeta' ) , {
8695 filename : mainFile ,
8796 meta : pkg . lcMeta ,
0 commit comments