-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup-plugin-browserify.js
29 lines (23 loc) · 1.13 KB
/
rollup-plugin-browserify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const browserify = require('browserify');
const fs = require('fs')
export default function cjsToBrowserify () {
return {
name: 'cjs-to-browserify', // this name will show up in warnings and errors
// resolveId ( source ) {
// if (source === 'virtual-module') {
// return source; // this signals that rollup should not ask other plugins or check the file system to find this id
// }
// return null; // other ids should be handled as usually
// },
writeBundle (writeBundleObj) {
console.log('===========================编译完成了writeBundleObj============================')
console.log('`${__dirname}/${writeBundleObj.dir}/index.js`',`${__dirname}/${writeBundleObj.dir}/index.js`)
if(writeBundleObj.format === 'cjs'){
browserify({ entries: [`${__dirname}/${writeBundleObj.dir}/index.js`] }).bundle(function (err,buf) {
console.log('browserify运行出错了err:',err)
fs.writeFileSync(`${__dirname}/npm/index.js`,buf)
})
}
}
};
}