mirror of https://github.com/lukechilds/rollup.git
Rich Harris
10 years ago
7 changed files with 48 additions and 2 deletions
@ -1,6 +1,10 @@ |
|||
import { readFileSync } from 'sander'; |
|||
|
|||
export function defaultLoader ( path, options ) { |
|||
// TODO support plugins and transformers?
|
|||
return readFileSync( path, { encoding: 'utf-8' }); |
|||
// TODO support plugins e.g. !css and !json?
|
|||
const source = readFileSync( path, { encoding: 'utf-8' }); |
|||
|
|||
return options.transform.reduce( ( source, transformer ) => { |
|||
return transformer( source, path ); |
|||
}, source ); |
|||
} |
|||
|
@ -0,0 +1,21 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'accepts multiple transformer functions', |
|||
options: { |
|||
transform: [ |
|||
function ( code, path ) { |
|||
return code.replace( /MAGIC_NUMBER/g, 3 ); |
|||
}, |
|||
|
|||
function ( code, path ) { |
|||
return code.replace( /\d+/g, function ( match ) { |
|||
return 2 * +match; |
|||
}); |
|||
} |
|||
] |
|||
}, |
|||
exports: function ( exports ) { |
|||
assert.equal( exports.magicNumber, 6 ); |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
export default MAGIC_NUMBER; |
@ -0,0 +1,3 @@ |
|||
import foo from './foo'; |
|||
|
|||
export var magicNumber = foo; |
@ -0,0 +1,13 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'accepts a single transformer function', |
|||
options: { |
|||
transform: function ( code, path ) { |
|||
return code.replace( /MAGIC_NUMBER/g, 3 ); |
|||
} |
|||
}, |
|||
exports: function ( exports ) { |
|||
assert.equal( exports.magicNumber, 3 ); |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
export default MAGIC_NUMBER; |
@ -0,0 +1,3 @@ |
|||
import foo from './foo'; |
|||
|
|||
export var magicNumber = foo; |
Loading…
Reference in new issue