Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
watch config file, restart on changes
- Loading branch information
Showing
5 changed files
with
151 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ export default function batchWarnings () { | |
}); | ||
|
||
allWarnings = new Map(); | ||
count = 0; | ||
} | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import path from 'path'; | ||
import chalk from 'chalk'; | ||
import * as rollup from 'rollup'; | ||
import batchWarnings from './batchWarnings.js'; | ||
import relativeId from '../../../src/utils/relativeId.js'; | ||
import { handleError, stderr } from '../logging.js'; | ||
|
||
export default function loadConfigFile (configFile, silent) { | ||
const warnings = batchWarnings(); | ||
|
||
return rollup.rollup({ | ||
entry: configFile, | ||
external: id => { | ||
return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5,id.length) === '.json'; | ||
}, | ||
onwarn: warnings.add | ||
}) | ||
.then( bundle => { | ||
if ( !silent && warnings.count > 0 ) { | ||
stderr( chalk.bold( `loaded ${relativeId( configFile )} with warnings` ) ); | ||
warnings.flush(); | ||
} | ||
|
||
return bundle.generate({ | ||
format: 'cjs' | ||
}); | ||
}) | ||
.then( ({ code }) => { | ||
// temporarily override require | ||
const defaultLoader = require.extensions[ '.js' ]; | ||
require.extensions[ '.js' ] = ( m, filename ) => { | ||
if ( filename === configFile ) { | ||
m._compile( code, filename ); | ||
} else { | ||
defaultLoader( m, filename ); | ||
} | ||
}; | ||
|
||
const configs = require( configFile ); | ||
if ( Object.keys( configs ).length === 0 ) { | ||
handleError({ | ||
code: 'MISSING_CONFIG', | ||
message: 'Config file must export an options object, or an array of options objects', | ||
url: 'https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file' | ||
}); | ||
} | ||
|
||
require.extensions[ '.js' ] = defaultLoader; | ||
|
||
return Array.isArray( configs ) ? configs : [configs]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters