系列文章目录
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
使用webpack
- 创建一个webpack-study文件件夹
- 导入idea
- 创建一个名为modules的目录,用于放置js模块等资源
- 在modules下创建模块文件,如hello.js,用于编写js模块代码
// 暴露一个方法:sayHi
export.sayHi=function(){
document.write='<h1>你好</h1>';
};
- 在modules下创建一个名为main.js的入口文件,用于打包时设置entry属性
// require 导入一个模块,就可以调用这个模块的方法
var hello = require(./hello);
hello.sayHi;
- 在项目目录创建一个名为webpack-config.js配置文件,用于webpack命令打包
module.exports={
entry='./modules/main.js';
output:{
filename='./js/bundle.js';
};
};
- 在项目目录下创建一个HTML页面,导入WebPack打包的js文件
<script src='dist/js/bundle.js'></script>