-
Notifications
You must be signed in to change notification settings - Fork 40
/
.rollup.js
36 lines (30 loc) · 937 Bytes
/
.rollup.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
30
31
32
33
34
35
36
import babel from 'rollup-plugin-babel'
export default {
input: 'src/index.js',
output: [
{ file: 'index.cjs', format: 'cjs', exports: 'default', sourcemap: false, strict: false },
{ file: 'index.mjs', format: 'esm', sourcemap: false, strict: false }
],
plugins: [
patchBabelPluginSyntaxImportMeta(),
babel({
presets: [
['@babel/env', { modules: false, targets: { node: 8 } }]
]
})
]
}
function patchBabelPluginSyntaxImportMeta () {
return {
name: 'patch-babel-plugin-syntax-import-meta',
renderChunk (code, chunk, options) {
const currentUrlMatch = /var url = require\('url'\);([\W\w]+)const currentURL[^\n]+\n(const currentFilename)[^\n]+/
const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code)
if (shouldTransformImportMeta) {
const updatedCode = code.replace(currentUrlMatch, '$1$2 = __filename;')
return updatedCode
}
return null
}
}
}