用法:css
const path = require('path');
module.exports={
output:{
filename:'bundle.js'
},
module:{
rules:[
{test:/\.txt$/,use:'raw-loader'} //test:指定匹配规则 , use:指定使用的loader名称
]
}
}
复制代码
用法:html
const path = require('path');
module.exports = {
output: {
filename:'bundle.js'
},
plugins:[
new HtmlWebpackPlugin({
template:'./src/index.html'
})
]
}
复制代码
解析es6的语法须要babel-loader,而babel-loader依赖于babel,因此须要创建babel的配置文件.babelrcreact
{
"presets":[],//presets为一系列babel plugins的集合
"plugins":[] //一个plugin对应一个功能
}
复制代码
-D:--save devwebpack
{
"presets":[
"@babel/preset-env" //es6的babel preset配置
]
}
复制代码
module.exports = {
entry:{...},
output:{...},
mode:"production",
module:{
rules:[
{test:/\.js$/,use:'babel-loader'}
]
}
}
复制代码
{
presets:[
"@babel/preset-react"
]
}
复制代码
'use strict'
import React from 'react';
import ReactDom from 'react-dom';
class Search extends React.Component {
render(){
return <div>Search Test</div>
}
}
ReactDom.render(
<Search/>,
document.getElementById('root')
)
复制代码
添加插件html-webpack-plugin,自动解析模板,不用每次去建立htmlgit
'use strict'
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry:{...},
output:{...},
module:{rules:[...]},
plugins:[
new HtmlWebpackPlugin({
template:'./public/index.html' //模板
})
]
}
复制代码
github源码:github.com/logmei/webp…