const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = env => {
let appName = 'pk';
return {
//devtool: env?'':'source-map', //打包不需要sourcemap
devtool: 'source-map', //打包不需要sourcemap
devServer: {
contentBase: './build',
host: '0.0.0.0',
port: 80,
hot: true
},
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'static/'+ appName +'/js/[hash].js'
},
plugins: [
// 指定模板路径 他会新建一份 html和ico 输出到dist
new HtmlWebpackPlugin({
// 压缩相关文件
// minify: {
// },
filename: 'index.html',
template: 'src/index.html',
favicon: 'src/favicon.ico'
})
],
module: {
rules: [
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [{
loader: 'file-loader',
options: {
name: 'static/'+appName+'/images/[sha1:hash:hex:20].[ext]'
}
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [{
loader:'file-loader',
options: {
name: 'static/'+appName+'/fonts/[sha1:hash:hex:20].[ext]'
}
}]
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ["@babel/preset-env", "@babel/preset-react"]
}
}
}
]
}
}
};