Answer the question
In order to leave comments, you need to log in
How to configure webpack for this task?
By default, Webpack (we are talking about v. 5.22.0) puts the build in an anonymous function. I need to make a build in the form of a plugin that could be connected in an html file and initialized in this way:
<script src="widget.js"></script> // Подключение плагина
<script>
new Widget().init() // Инициализация
</script>
module.exports = {
...
entry: './app.js',
output: {
library: 'Widget',
filename: 'widget.js',
path: PATH.resolve(__dirname, 'dist')
}
}
new Widget.default().init()
new Widget().init()
export default class Widget {
constructor() {...}
init() {...}
}
Answer the question
In order to leave comments, you need to log in
see ready plugin config here https://github.com/delphinpro/cool-menu/blob/maste...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question