2021-12-12 15:38:17 +00:00
|
|
|
import cjs from 'rollup-plugin-cjs-es';
|
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
|
import iife from 'rollup-plugin-iife';
|
|
|
|
import {terser} from 'rollup-plugin-terser';
|
|
|
|
import output from 'rollup-plugin-write-output';
|
2021-12-12 15:14:31 +00:00
|
|
|
|
|
|
|
import escapeRe from 'escape-string-regexp';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
input: {
|
2021-12-12 15:38:17 +00:00
|
|
|
'codemirror/base': 'src/codemirror/base.mjs',
|
|
|
|
'codemirror/edit': 'src/codemirror/edit.mjs',
|
2021-12-12 15:14:31 +00:00
|
|
|
},
|
|
|
|
output: {
|
2021-12-12 15:38:17 +00:00
|
|
|
dir: 'dist',
|
|
|
|
chunkFileNames: 'chunks/[name]-[hash].js',
|
2021-12-12 15:14:31 +00:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
resolve(),
|
|
|
|
cjs({nested: true}),
|
|
|
|
iife(),
|
|
|
|
terser({module: false}),
|
|
|
|
output([
|
|
|
|
{
|
|
|
|
test: /codemirror\/edit\.js/,
|
|
|
|
target: 'dist/edit.html',
|
2021-12-12 15:38:17 +00:00
|
|
|
handle: (content, {htmlScripts}) => replaceLine(content, '<!-- codemirror-edit -->', htmlScripts),
|
2021-12-12 15:14:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /codemirror\/base\.js/,
|
|
|
|
target: 'dist/install-usercss/install-usercss.js',
|
|
|
|
handle: (content, {scripts}) => replaceLine(content, '// codemirror-base',
|
2021-12-12 15:38:17 +00:00
|
|
|
JSON.stringify(scripts.map(resolvePath('/install-usercss/install-usercss.js')))),
|
|
|
|
},
|
|
|
|
]),
|
2021-12-12 15:25:00 +00:00
|
|
|
],
|
2021-12-12 15:38:17 +00:00
|
|
|
preserveEntrySignatures: false,
|
2021-12-12 15:14:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function resolvePath(base) {
|
|
|
|
return id => {
|
|
|
|
const isAbs = base.startsWith('/');
|
|
|
|
const u = new URL(id, `http://dummy${isAbs ? '' : '/'}${base}`);
|
|
|
|
return isAbs ? u.pathname : u.pathname.slice(1);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function replaceLine(content, marker, repl) {
|
2021-12-12 15:38:17 +00:00
|
|
|
return content.replace(new RegExp(`\\S.*${escapeRe(marker)}`), `${repl} ${marker}`);
|
2021-12-12 15:14:31 +00:00
|
|
|
}
|