Sample project to bundle your js in IIFE format and use it in browser.
yarn install
yarn run build
This will package your js files from src folder and put it in dist.
In Development Mode with http-server and rollup watch support
yarn run dev
For Production
yarn run build
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
name: 'mybundle',
sourcemap: true,
},
plugins: [
commonjs(),
resolve(),
babel({
exclude: 'node_modules/**' // only transpile our source code
})
]
};
If you put following declaration in rollup.config.js then faker will be treated as external and will not be loaded with your library
external: ['faker']
IIFE bundle will be available with name mybundle and used as follows in index.html
<script src="bundle.js"></script>
<script type="text/javascript">
function foo(){
mybundle.sayHello();
}
function bar(){
mybundle.sayHi();
}
function print(){
document.getElementById('result').innerHTML = mybundle.printDemo();
}
</script>