Reputation: 707
I created a module like this:
export default () => console.log('hello my_module~!')
The settings in the webpack.config.js
file are as follows:
module.exports = {
// ...
output: {
// ...
library: 'hello',
libraryTarget: 'var'
}
}
And in the html file, the script code is:
<script src="/output_my_module.js"></script>
<script>
hello.default(); // yea~ It's work!!
</script>
But the way I want is as follows:
hello(); // I want use like this.
What should I do? I read webpack's doc but couldn't find a way. (Maybe I missed it because my English wasn't good...)
Upvotes: 1
Views: 1045
Reputation: 1385
You should put libraryExport to your config.
library: 'hello',
libraryTarget: 'var',
libraryExport: 'default'
Upvotes: 2