您的位置:首页 > Web前端 > Webpack

webpack 基本配置 - 01

2016-09-26 21:18 295 查看
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CleanPlugin = require('clean-webpack-plugin');

const PATH = {
src:path.join(__dirname, 'src'),
build:path.join(__dirname, 'build')
}

module.exports ={

entry:{
app:PATH.src,
// vendor:[
//     PATH.src+'/common/jquery',
//     PATH.src+'/common/layer/layer'
// ]
},
output:{
// publicPath 配置上线时的路径
// 可有效解决css loader 和url loader路径不一致问题
publicPath:'/',
path:PATH.build,
filename:'./js/[name].js',
chunkFilename:'./js/[name].chunck.js'
},
module:{
loaders:[
{
test:/\.(png|gif|jpg|jpeg)$/,
exclude: /node_modules/,
loader:'url?limit=7000&name=images/[name].[ext]',
},
{
test:/\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
}
]
},
plugins:[
new CleanPlugin(['build']),
new ExtractTextPlugin('css/[name].css'),
new HtmlWebpackPlugin({
title:'webpack demo',
}),
// 压缩
// new webpack.optimize.UglifyJsPlugin({
//     compress:{
//         warnings:false
//     }
// })
],
devServer: {
compress:true,
inline: true,
compiler:{
hot:true
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: