webpack资源加载常用配置
const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, module: { rules:[ // css加载 //包下载命令:npm install --save-dev style-loader css-loader { test:/\.css$/, use:[ 'style-loader', 'css-loader', ] }, // 图片加载及字体加载 //包下载命令:npm install --save-dev file-loader { test:/\.(png|jpg|gif)$/, use:[ 'file-loader' ] }, { test:/\.(woff|woff2|eot|ttf|otf)$/, use:[ 'file-loader' ] }, // 数据加载 (json是内置的,所以无需下载对应的包) //包命令:npm install --save-dev csv-loader xml-loader { test:/\.xml$/, use:[ 'xml-loader' ] }, { test:/\.(csv|tsv)$/, use:[ 'csv-loader' ] } ] } };
想做一定有方法,不想做一定有理由。