1 Star 0 Fork 1

yunhaiai/jsPDF

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
Sanders DeNardi 提交于 2020-02-06 11:25 . fix merge conflicts
const rollupResolve = require('rollup-plugin-node-resolve');
const rollupBabel = require('rollup-plugin-babel');
const buble = require('rollup-plugin-buble');
const sizes = require('rollup-plugin-sizes');
const path = require('path');
// Monkey patching filesaver and html2canvas
function monkeyPatch() {
return {
transform: (code, id) => {
const file = path.parse(id).base;
// Only one define call per module is allowed by requirejs so
// we have to remove calls that other libraries make
if (file === 'FileSaver.js') {
code = code.replace(/define !== null\) && \(define.amd != null/g, '0')
} else if (file === 'html2canvas.js') {
code = code.replace(/&&\s+define.amd/g, '&& define.amd && false')
}
return code
}
}
}
// Rollup removes local variables unless used within a module.
// This plugin makes sure specified local variables are preserved
// and kept local. This plugin wouldn't be necessary if es2015
// modules would be used.
function rawjs(opts, context) {
opts = opts || {}
return {
transform: (code, id) => {
var variable = opts[id.split('/').pop()]
if (!variable) return code
var keepStr = '/*rollup-keeper-start*/' + context + '.tmp=' + variable +
';/*rollup-keeper-end*/'
return code + keepStr
},
transformBundle: (code) => {
for (var file in opts) {
var r = new RegExp(opts[file] + '\\$\\d+', 'g')
code = code.replace(r, opts[file])
}
var re = /\/\*rollup-keeper-start\*\/.*\/\*rollup-keeper-end\*\//g
return code.replace(re, '')
}
}
}
module.exports = {
input: './main.js',
plugins: [
rollupResolve(),
monkeyPatch(),
rawjs({
'jspdf.js': 'jsPDF',
'filesaver.tmp.js': 'saveAs',
'filesaver.js': 'saveAs',
'deflate.js': 'Deflater',
'zlib.js': 'FlateStream',
'BMPDecoder.js': 'BmpDecoder',
'omggif.js': 'GifReader',
'JPEGEncoder.js': 'JPEGEncoder',
'WebPDecoder.js': 'WebPDecoder',
'html2pdf.js': 'html2pdf'
}, 'window'),
rollupBabel(),
buble(),
sizes()
],
nodePlugins: [
rollupResolve(),
monkeyPatch(),
rawjs({
'jspdf.js': 'jsPDF',
'filesaver.tmp.js': 'saveAs',
'filesaver.js': 'saveAs',
'deflate.js': 'Deflater',
'zlib.js': 'FlateStream',
'BMPDecoder.js': 'BmpDecoder',
'omggif.js': 'GifReader',
'JPEGEncoder.js': 'JPEGEncoder',
'WebPDecoder.js': 'WebPDecoder',
'html2pdf.js': 'html2pdf'
}, 'global'),
rollupBabel(),
buble(),
sizes()
],
output: [
{
name: 'namebndl',
format: 'iife',
file: './lib/index.js',
sourcemap: false
}
]
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhongchengyi/jsPDF.git
[email protected]:zhongchengyi/jsPDF.git
zhongchengyi
jsPDF
jsPDF
master

搜索帮助