webpack配置

来源:互联网 发布:易语言网页填表源码 编辑:程序博客网 时间:2024/05/19 02:45

webpack.common.js

const path = require('path');const HtmlWebpackPlugin = require('html-webpack-plugin');const CleanWebpackPlugin = require('clean-webpack-plugin');const webpack = require('webpack');module.exports = {    entry: {        index: "./src/index.js",        another: "./src/anther-module.js",        vendor: [            'lodash'        ]    },    plugins: [        new CleanWebpackPlugin(['dist']),        new HtmlWebpackPlugin({            title: "code spliting"        }),        new webpack.HashedModuleIdsPlugin(),        new webpack.optimize.CommonsChunkPlugin({            name: 'vendor'        }),        new webpack.optimize.CommonsChunkPlugin({            name: 'common'        })    ],    module: {        loaders: [{            test: /\.(js|jsx)$/,            exclude: /node_modules/,            loader: 'babel-loader'        }],    },    output: {        filename: '[name].[chunkhash].js',        chunkFilename: '[name].[chunkhash].js',        path: path.resolve(__dirname, 'dist')    }};

webpack.prod.js

const merge = require('webpack-merge');const common = require('./webpack.common.js');const UglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin');const webpack = require('webpack');module.exports = merge(common, {    plugins: [        new UglifyjsWebpackPlugin({            sourceMap: true        }),        new webpack.DefinePlugin({            'process.env': {                'NODE_ENV': JSON.stringify('production')            }        })    ]});

webpack.dev.js

const merge = require('webpack-merge');const common = require('./webpack.common.js');module.exports = merge(common, {    devtool: "inline-source-map",    devServer: {        contentBase: "./dist"    }});
原创粉丝点击