Skip to content

Instantly share code, notes, and snippets.

@srph
Forked from dreyescat/index.html
Created February 3, 2017 17:38
Show Gist options
  • Save srph/dfd341e624f3c87a8613a0e44877451a to your computer and use it in GitHub Desktop.
Save srph/dfd341e624f3c87a8613a0e44877451a to your computer and use it in GitHub Desktop.
Webpack config to expose bundle in a variable in the global context
<html>
<head>
</head>
<body>
<script src="lib/yourlib.js"></script>
<script>
window.onload = function () {
EntryPoint.run();
};
</script>
</body>
</html>
module.exports = {
run: function () {
console.log('run from library');
}
};
{
"name": "test-webpack-library",
"version": "1.0.0",
"description": "",
"main": "./lib/yourlib.js",
"scripts": {
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "MIT"
}
var webpack = require('webpack');
module.exports = {
entry: './index.js',
output: {
path: './lib',
filename: 'yourlib.js',
libraryTarget: 'var',
library: 'EntryPoint'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment