Last active
January 11, 2023 09:08
-
-
Save Karlbovski/dfa1bab2cb8479b7d6bf33e827ce6e94 to your computer and use it in GitHub Desktop.
11ty Starter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```js | |
const | |
jsMain = 'js/main.js', | |
rollup = require('rollup'), | |
terser = require('rollup-plugin-terser').terser, | |
inputOptions = { | |
input: './src/' + jsMain | |
}, | |
outputOptions = { | |
format: 'es', | |
sourcemap: dev, | |
plugins: [ | |
terser({mangle: { | |
toplevel: true | |
}, | |
compress: { | |
drop_console: !dev, | |
drop_debugger: !dev | |
}, | |
output: { | |
quote_style: 1 | |
} | |
}) | |
] | |
}; | |
module.exports = class { | |
data(){ | |
return{ | |
permalink: jsMain, | |
eleventyExcludeFromCollections: true | |
}; | |
} | |
async render(){ | |
const | |
bundle = await rollup.rollup(inputOptions), | |
{ output } = await bundle.generate(outputOptions), | |
out = output.length && output[0]; | |
// process images | |
console.log('javascript.11ty.js - Javascript processing'); | |
let code = ''; | |
if(out){ | |
// JS code | |
code = out.code; | |
// inline sourcemap | |
if(out.map){ | |
let b64 = new Buffer.from(out.map.toString()); | |
code += '//# sourceMappingURL=data:application/json;base64,' + b64.toString('base64'); | |
} | |
} | |
return code; | |
} | |
}; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment