Last active
June 16, 2021 00:07
-
-
Save flashlin/7e86d5fdb2c0d659d497b9927ea9eca8 to your computer and use it in GitHub Desktop.
[Calling webpacked code from outside (HTML script tag)] #javascript
This file contains hidden or 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
<html> | |
<head> | |
</head> | |
<body> | |
<script src="lib/yourlib.js"></script> | |
<script> | |
window.onload = function () { | |
EntryPoint.run(); | |
}; | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
module.exports = { | |
run: function () { | |
console.log('run from library'); | |
} | |
}; |
This file contains hidden or 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
{ | |
"name": "test-webpack-library", | |
"version": "1.0.0", | |
"description": "", | |
"main": "./lib/yourlib.js", | |
"scripts": { | |
"build": "webpack" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "MIT" | |
} |
This file contains hidden or 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
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