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
瀏覽器