Webpack不断编译节点模块

时间:2017-06-02 19:45:58

标签: webpack webpack-2

我正在从webpack v1.13.2转换到2.6.1,我已经关注了Migr ating from v1 to v2文档,但由于某种原因我无法找到webpack继续编译节点模块(而我已经排除了文件夹)。

希望得到一些帮助,因为目前它正在以错误和非常缓慢的(40秒)构建时间杀死我,平均时间为4.8秒。捆绑大小也从4.1mb上升到10.1mb。

文件夹结构

  • node_modules
  • webpack.config.js
  • app(又名src)
  • build(aka dist)
  • 出口

我的超级简单webpack.config.js文件

const path = require('path');

module.exports = {
    devtool: 'cheap-eval-source-map',

    context: path.resolve(__dirname, 'app', 'js'),

    entry: {
        bundle: 'index.js'
    },

    resolve: {
        modules: [
            path.join('app', 'js'),
            'node_modules'
        ]
    },

    output: {
        path: path.join(__dirname, 'build', 'js'),
        filename: 'react.js',
        sourceMapFilename: 'react.js.map'
    },

    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: [
                    '/(node_modules)/',
                    '/(bower_components)/'
                ],
                loader: 'babel-loader',
                options: {
                    presets: [
                        'babel-preset-react',
                        'babel-preset-es2015',
                        'babel-preset-stage-0'
                    ]
                }
            }
        ]
    }
};

错误示例(您可以看到它来自编译react-dropzone

ERROR in C:/xampp/htdocs/wizer_sorted/dashboard/~/react-dropzone/dist/index.js
Module build failed: ReferenceError: Unknown plugin "add-module-exports" specified in "C:\\xampp\\htdocs\\wizer_sorted\\dashboard\\node_modules\\react-dropzone\\.babelrc" at 0, attempted to resolve relative to "C:\\xampp
\\htdocs\\wizer_sorted\\dashboard\\node_modules\\react-dropzone"
    at C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\options\option-manager.js:180:17
    at Array.map (native)
    at Function.normalisePlugins (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
    at OptionManager.mergeOptions (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
    at OptionManager.init (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
    at File.initOptions (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\index.js:212:65)
    at new File (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\file\index.js:135:24)
    at Pipeline.transform (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    at transpile (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-loader\lib\index.js:48:20)
    at Object.module.exports (C:\xampp\htdocs\wizer_sorted\dashboard\node_modules\babel-loader\lib\index.js:163:20)
 @ ./components/molecules/Upload/index.js 23:21-46
 @ ./components \.\/(atoms|molecules|organisms)\/[^\/]+\/index\.js
 @ ./components/index.js
 @ ./routing/app.js
 @ ./routing/routes.js
 @ ./index.js

更新1

在实现正确的Rules.exclude之后,感谢@AndrewLi,构建时间下降到大约15秒,但构建大小保持不变,我仍然可以看到那些不应该存在的东西。见下面的截图。 enter image description here

更新2

我正在将devtool: 'eval'devtoo: 'cheap-eval-source-map'进行比较。实际上,构建大小已恢复正常。与webpack v1.13.2 5秒相比,唯一保持不变的是构建速度仍超过 15秒

0 个答案:

没有答案