File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222} from '../lib/configuration/defaults' ;
2323import { FileSystemReader } from '../lib/readers' ;
2424import { ERROR_PREFIX } from '../lib/ui' ;
25+ import { isModuleAvailable } from '../lib/utils/is-module-available' ;
2526import { AbstractAction } from './abstract.action' ;
2627import webpack = require( 'webpack' ) ;
2728
@@ -261,13 +262,10 @@ export class BuildAction extends AbstractAction {
261262 webpackRef : typeof webpack ,
262263 ) => webpack . Configuration {
263264 const pathToWebpackFile = join ( process . cwd ( ) , webpackPath ) ;
264- try {
265- return require ( pathToWebpackFile ) ;
266- } catch ( err ) {
267- if ( webpackPath !== defaultPath ) {
268- throw err ;
269- }
265+ const isWebpackFileAvailable = isModuleAvailable ( pathToWebpackFile ) ;
266+ if ( ! isWebpackFileAvailable && webpackPath === defaultPath ) {
270267 return ( { } ) => ( { } ) ;
271268 }
269+ return require ( pathToWebpackFile ) ;
272270 }
273271}
Original file line number Diff line number Diff line change @@ -60,10 +60,13 @@ export class AssetsManager {
6060
6161 const filesToCopy = assets . map < AssetEntry > ( ( item ) => {
6262 let includePath = typeof item === 'string' ? item : item . include ! ;
63- let excludePath = typeof item !== 'string' && item . exclude ? item . exclude : undefined ;
63+ let excludePath =
64+ typeof item !== 'string' && item . exclude ? item . exclude : undefined ;
6465
6566 includePath = join ( sourceRoot , includePath ) . replace ( / \\ / g, '/' ) ;
66- excludePath = excludePath ? join ( sourceRoot , excludePath ) . replace ( / \\ / g, '/' ) : undefined ;
67+ excludePath = excludePath
68+ ? join ( sourceRoot , excludePath ) . replace ( / \\ / g, '/' )
69+ : undefined ;
6770
6871 return {
6972 outDir : typeof item !== 'string' ? item . outDir || outDir : outDir ,
Original file line number Diff line number Diff line change 1+ export function isModuleAvailable ( path : string ) : boolean {
2+ try {
3+ require . resolve ( path ) ;
4+ return true ;
5+ } catch {
6+ return false ;
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments