react.js - webpack 每次修改都要扫描 node_modules

查看:265
本文介绍了react.js - webpack 每次修改都要扫描 node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

每次修改东西,都会重新扫描 react/lib
这些库已经使用 CommonsChunkPlugin 抽离出来了

const path = require('path');
const webpack = require('webpack');
const config = require('../config/config');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
      app: [
      config.utils_paths.client('index.js'),
       'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000'
      ],
      vendor: ["react","react-dom"]
  },
  devtool: "source-map",
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, config.utils_paths.dist()),
    publicPath: '/'
  },
  devServer: {
    hot: true,
    contentBase: path.resolve(__dirname, config.utils_paths.dist()),
    publicPath: '/'
  },
  module: {
      loaders: [{
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      loader: 'babel-loader'
    }]
  },
  plugins: [
      new webpack.optimize.CommonsChunkPlugin({name:['vendor','manifest']}),
      new HtmlWebpackPlugin({
        template: config.utils_paths.client('index.html'),
        hash: false,
        filename: 'index.html',
        inject: 'body',
        minify: {
          collapseWhitespace: true
        }
      }),
      new webpack.HotModuleReplacementPlugin()
  ]
};

解决方案

试试 DllPlugin。SF 有一篇很不错的博文介绍:Webpack 的 dll 功能

这篇关于react.js - webpack 每次修改都要扫描 node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆