forked from csstools/postcss-normalize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rollup.js
39 lines (33 loc) · 1015 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
37
38
39
import babel from 'rollup-plugin-babel';
export default {
input: 'src/index.js',
output: [
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true, strict: false },
{ file: 'index.esm.mjs', format: 'esm', sourcemap: true, strict: false }
],
plugins: [
patchBabelPluginSyntaxImportMeta(),
babel({
plugins: [
['@babel/plugin-syntax-import-meta']
],
presets: [
['@babel/preset-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]+\nconst currentFilename[^\n]+/;
const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code);
if (shouldTransformImportMeta) {
const updatedCode = code.replace(currentUrlMatch, '$1const currentFilename = __filename;');
return updatedCode;
}
return null;
}
};
}