1.为何咱们须要打包?css
2.webpack特色html
3.正式使用webpack前的准备webpack
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Webpack-test</title> </head> <body> <script src="bundle.js"></script> </body> </html>
4.打包js文件web
document.write('hello webpack!');
const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') } };
{ ... "scripts": { "build": "webpack" }, ... }
5.打包css文件正则表达式
const path = require('path'); module.exports = { //入口 entry: './src/index.js', //输出 output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, //模块处理 module: { loaders: [{ //使用正则表达式检测文件后缀名 test: /\.css$/, //使用两个loader处理css文件,先执行css-loader(对css文件读取,处理url),再执行style-loader(读取css文件应用到页面上,即显示样式) loaders: ['style-loader', 'css-loader'] }] } };
require('./style.css');
6.加载图片:npm install --save-dev file-loader
npm
7.加载字体json
8.加载数据:npm install --save-dev csv-loader xml-loader
浏览器