美文网首页
webpack 配置参考(dev)

webpack 配置参考(dev)

作者: wlianfu | 来源:发表于2018-02-13 10:47 被阅读3次

我的 webpack 配置文件(React 项目),自己动手搭的,留作参考

const webpack = require('webpack')
const path = require('path')
const ManifistPlugin = require('webpack-manifest-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

const modules = require('./config/base')

const config = {
  entry: [
    'babel-polyfill',
    'react-hot-loader/patch',
    'webpack-dev-server/client?http://localhost:9000',
    path.join(__dirname, '/src/container/render')
  ],
  output: {
    publicPath: 'http://localhost:9000/',
    path: path.join(__dirname, '/dist'),
    filename: '[name].[hash:5].js'
  },
  module: modules,
  resolve: {
    extensions: ['.js', '.jsx', '.json', '.css', '.scss', '.sass'],
    alias: {
      '@': path.join(__dirname, '/src/container')
    }
  },
  devServer: {
    publicPath: path.join(__dirname, '/dist'),
    contentBase: path.join(__dirname, '/dist'),
    historyApiFallback: true,
    port: 9000,
    hot: true,
    inline: true,
    stats: 'normal'
  },
  plugins: [
    new ManifistPlugin(),
    new ExtractTextPlugin('/style.css'),
    new HtmlWebpackPlugin({
      template: path.join(__dirname, '/index.html')
    }),
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin({}),
    new webpack.SourceMapDevToolPlugin({
      filename: '[name].[hash:5].map'
    })
  ]
}

module.exports = config

相关文章

网友评论

      本文标题:webpack 配置参考(dev)

      本文链接:https://www.haomeiwen.com/subject/qvrjtftx.html