码迷,mamicode.com
首页 > Web开发 > 详细

Webpack配置

时间:2020-04-09 16:45:18      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:gif   node   cti   manifest   one   bundle   product   try   too   

const path = require(‘path‘);
const Webpack = require(‘webpack‘);
const HtmlWebpackPlugin = require(‘html-webpack-plugin‘);
const ManifestPlugin = require(‘webpack-manifest-plugin‘);
const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin‘);

module.exports = {
  entry: path.resolve(__dirname, ‘../src/index.jsx‘),
  output: {
    filename: "[name].bundle.js",
    path: path.resolve(__dirname, ‘dist‘),
    publicPath: process.env === ‘production‘ ? ‘dist‘ : ‘/‘
  },
  devtool: ‘inline-source-map‘,
  devServer: {
    contentBase: ‘./dist‘,
    hot: true,
    inline: true,
    open: true,
    overlay: true,
    host: ‘0.0.0.0‘,
    proxy: {}
  },
  resolve: {
    extensions: [‘.less‘, ‘.jsx‘, ‘.js‘],
    alias: {
      ‘@‘: ‘src‘,
      ‘components‘: ‘src/components‘,
      ‘container‘: ‘src/container‘,
      ‘view‘: ‘src/view‘,
      ‘common‘: ‘src/common‘,
      ‘base‘: ‘src/base‘
    }
  },
  module: {
    rules: [
      { test: ‘/\.css$/‘, use: [‘css-loader‘, ‘style-loader‘] },
      { test: ‘/\.jsx/‘, use: [‘babel-loader‘] },
      { test: ‘/\.(png|jpg|svg|gif|woff|woff2|eot|ttf|otf)$/‘, use: [‘file-loader‘] }
    ]
  },
  plugins: [
    new ManifestPlugin(),
    new HtmlWebpackPlugin({
      title: "Webpack App"
    }),
    new UglifyJsPlugin({
      sourceMap: true
    }),
    new Webpack.optimize.CommonsChunkPlugin({
      name: ‘manifest‘
    }),
    new Webpack.HotModuleReplacementPlugin(),
    new Webpack.DefinePlugin({
      ‘process.env.NODE_ENV‘: JSON.stringify(‘production‘)
    }),
  ]
};

  

Webpack配置

标签:gif   node   cti   manifest   one   bundle   product   try   too   

原文地址:https://www.cnblogs.com/ginkgo-leaves/p/12667807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!