我想通過使用npm模塊在瀏覽器中運行simpleWeather jQuery插件。我聽說我需要使用捆綁器,所以我安裝了Webpack。如何webpack npm模塊?
這是文件夾結構:
- 天氣
- JS
- index.js
- node_modules
- 的jquery
- simpleweather
- 的index.html
- 的package.json
- webpack.config.js
- JS
的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>simpleWeather.minimum.js</title>
<style>
</style>
</head>
<body>
<div id="weather"></div>
<script src="js/bundle.js"></script>
</body>
</html>
索引.js:
$(document).ready(function() {
$.simpleWeather({
location: 'Austin, TX',
woeid: '',
unit: 'f',
success: function(weather) {
html = '<p>'+weather.temp+'°'+weather.units.temp+'</p>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
});
webpack.config.js:
module.exports = {
entry: "./js/index.js",
output: {
filename: "js/bundle.js"
}
}
這不會在瀏覽器中工作,我想,我需要一些不同的方式配置的WebPack。
我需要做什麼?
建議閱讀http://blog.andrewray.me/webpack-when-to-use-and-why/ –