var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpack = require('webpack');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
entry: {
'index':'./app/index.js',
'css':'./app/index.less'
},
resolve:{
extensions:['.js'],
alias: {
//设置全局jquery插件;
jquery: path.resolve(__dirname,'./bower_components/jquery/dist/jquery.js') //绝对路径;
},
module: {
rules: [
{
test: /\.html$/,
use: ['html-loader']
},
{
test: /\.(png|jpg|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?[\s\S]+)?$/,
use: "file-loader?name=[name][hash].[ext]&outputPath=images/"
},
{
test: /\.less$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use: ['css-loader', 'less-loader']
})
}
]} ,
plugins: [
new ExtractTextPlugin({
filename:"styles.css",
allChunks:true }),
new HtmlWebpackPlugin({
title:'hello',
filename: 'test.html',
template: 'app/index.html' }),
new webpack.optimize.CommonsChunkPlugin({
name: ['index'] }),
new UglifyJSPlugin(),
new webpack.ProvidePlugin({
$: 'jquery' }), //文件里遇见‘$’加载jquery
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g, //正则匹配后缀.css文件;
cssProcessor: require('cssnano'), //加载‘cssnano’css优化插件;
cssProcessorOptions: { discardComments: {removeAll: true } }, //插件设置,删除所有注释;
canPrint: true //设置是否可以向控制台打日志,默认为true;
} ) ],
devServer: {
stats: 'errors-only',
contentBase:'./',
disableDotRule:true
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
chunkFilename:'js/[name].js'
}
};
webpack-config
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- webpack是前端资源模块化管理和打包工具,在某种程度上来说,是专门为前端开发量身打造的。在webpack出现之...
- 1.下载vue-cli vue-cli的使用与详细介绍,可以到github上获取https://github.co...