Skip to content

Instantly share code, notes, and snippets.

@Karlbovski
Last active January 11, 2023 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karlbovski/dfa1bab2cb8479b7d6bf33e827ce6e94 to your computer and use it in GitHub Desktop.
Save Karlbovski/dfa1bab2cb8479b7d6bf33e827ce6e94 to your computer and use it in GitHub Desktop.
11ty Starter
```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