1,webpack 每日一练,最基本的使用
2,创建新项目
npm init
3,安装用到的包
npm install webpack@3.10.0 style-loader css-loader --save
4,创建主页面 index.html
<!--Created by Sukla on 2018/3/1.-->
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>
5,创建打包入口文件 entry.js
/**
* Created by Sukla on 2018/3/1.
*/
require('./style.css')
document.write(123)
document.write(require('./module.js'))
6,创建样式表 style.css
body{
background: #005aa0;
}
7,创建脚本文件 module.js
/**
* Created by Sukla on 2018/3/1.
*/
module.exports=3456
8,创建webpack打包配置文件 webpack.config.js
/**
* Created by Sukla on 2018/3/1.
*/
var webpack=require('webpack')
module.exports={
entry:'./entry.js',
output:{
path:__dirname,
filename:'bundle.js'
},
module:{
loaders:[
{test:/\.css$/,loader:'style-loader!css-loader'}
]
},
plugins:[
new webpack.BannerPlugin('This file is created by Sukla.')
]
}
9,开始打包
webpack --progress --colors
10,结果