Figured out how to achieve tree-shaking. Use 'import * as foo'

parent f22d1f75
import dukboot from 'dukboot'
import { loop } from './runtime2/scheduler.js'
// For convenience, we can just nab the whole namespace!
// Rollup is smart enough to know that 'streams' is not
// a regular object and instead will import only the exports we use
import * as streams from './runtime2/streams/index.js'
if (dukboot.thread.id() === 0) {
streams.ByteDuplexStream.sink(streams.ByteDuplexStream.source)
......
var dukboot = require('dukboot')
var { loop } = require('./runtime2/scheduler.js')
// Here, rollup is not smart enough to tree-shake - even if we use
// var { ByteDuplexStream } = require('./runtime2/streams/index.js')
// it imports the entire module and uses destructuring assignment.
// However we can still grab the whole namespace, which is convenient!
var streams = require('./runtime2/streams/index.js')
// Note: We can still import each file individually to do "manual" tree-shaking.
// var ByteDuplexStream = require('./runtime2/streams/byte-duplex-stream.js')
if (dukboot.thread.id() === 0) {
streams.ByteDuplexStream.sink(streams.ByteDuplexStream.source)
}
loop()
......@@ -22,3 +22,6 @@ export function loop () {
if (e.message !== "Queue complete.") log.log(e);
}
}
// for CommonJS functionality etc
export default { append, loop }
import { thread } from 'dukboot'
import { thread, log } from 'dukboot'
import { UnicodeThroughStream, ByteDuplexStream } from './runtime2/streams/index.js'
import { loop } from './runtime2/scheduler.js'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment