Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Webpack在bundle.js中包含未使用的库_Javascript_Webpack - Fatal编程技术网

Javascript Webpack在bundle.js中包含未使用的库

Javascript Webpack在bundle.js中包含未使用的库,javascript,webpack,Javascript,Webpack,我不明白为什么 包括未使用库的100KB大小: /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ ... ... 我将es6与babel和react一起使用,代码运行良好,只是试图缩小包 还使用跨库(节点/浏览器),使

我不明白为什么

包括未使用库的100KB大小:

/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
 * @license  MIT
 */
...
...
我将
es6
babel
react
一起使用,代码运行良好,只是试图缩小包


还使用跨库(节点/浏览器),使用
http
https
,但我认为这不是问题所在。

从webpack1迁移到webpack2时,我遇到了类似的问题。捆绑包大小从125kb增加到164kb(最小化)

看起来主要部分采用了缓冲区库,该库可能来自css加载程序,并添加了源映射支持


我打开了一个问题,看起来简单的解决方法是将
节点:{Buffer:false}
添加到webpack配置中。更多信息请访问:

您如何知道它未被使用?您可以检查捆绑包中使用它的内容。@zerkms hi,是交叉库,所有额外的代码都来自
http
https
,解决方案是将库与browserify捆绑在一起,使用选项。外部('http')。外部('https'),然后在网页包中像供应商一样使用结果库。。。
    'use strict';

/* eslint-env node */

const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const config = {
  addVendor: function (name, path) {
    this.resolve.alias[name] = path;
    this.module.noParse.push(new RegExp(`^${name}$`));
  },

  node: {
    Buffer: false,
    global: false,
    process: false,
    setImmediate: false
  },

  entry: {
    app: [
      './src/main.jsx'
    ],
    vendors: [
      'jquery',
      'semantic',
      'semantic.css',
      'react',
      'react-dom'
    ]
  },

  resolve: { alias: {} },

  output: {
    path: `${__dirname}/build`,
    publicPath: '/',
    filename: 'bundle.js'
  },

  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new CopyWebpackPlugin([{ from: './src/static', to: './' }]),
    new webpack.optimize.CommonsChunkPlugin('app', null, false),
    new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery'
    })
  ],

  module: {
    noParse: [],
    loaders: [
      {
        test: /\.(jsx)?$/,
        exclude: /node_modules/,
        loader: 'babel'
      },
      {
        test: /\.(js)$/,
        loader: 'babel',
        exclude: [/node_modules/, /bower_components/]
      },
      {
        test: /\.(css)$/,
        loader: 'style!css'
      },
      {
        test: /\.(scss)$/,
        loader: 'style!css!sass'
      },
      {
        test: /\.(less)$/,
        loader: 'style!css!less'
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000'
      }
    ]
  }
};

config.addVendor('jquery', `${__dirname}/bower_components/jquery/dist/jquery.min.js`);
config.addVendor('semantic', `${__dirname}/bower_components/semantic/dist/semantic.min.js`);
config.addVendor('semantic.css', `${__dirname}/bower_components/semantic/dist/semantic.min.css`);
config.addVendor('react', `${__dirname}/bower_components/react/react.min.js`);
config.addVendor('react-dom', `${__dirname}/bower_components/react/react-dom.min.js`);

module.exports = config;