brunch.io conventions.ignored 不尊重 node_modules

brunch.io conventions.ignored does not respect node_modules

我正在构建一个具有多个入口点的应用程序。这是一个 plugin/sideloading 反应架构。

我有一个基本的反应应用程序编译成 app.js 和 vendor.js 就好了。问题源于次要项目,主题,与一些相同的依赖项捆绑在一起。最值得注意的是 react 和 react-dom。我希望能够使用 conventions.ignored 来指示早午餐忽略特定的 node_modules 及其依赖项。不管我在 conventions.ignored 中输入的正则表达式如何,我仍然会在 theme_vendor.js 包中得到 react 和 react-dom。请参阅下面的配置:

const {theme_name} = require('./package.json');
module.exports = {
    sourceMaps: 'inline',
    files: {
        javascripts: {
            joinTo: {
                "theme.js": [
                    /^theme/,
                ],
                "theme_vendor.js": [
                    /^(?!theme)/,
                ],
            }
        },
        stylesheets: {
            joinTo: {
                'theme.css': ["theme/config/styles/index.scss"],
                'theme_ie11.css': ["theme/config/styles/ie.scss"],
            }
        }
    },
    conventions: {
        ignored: [
            /\/_/,
            "node_modules\/react",
            "node_modules\/react-dom",
        ],
    },
    plugins: {
        babel: {
            presets: ['es2015', 'stage-0', 'react'],
            plugins: [
                ['transform-runtime', {
                    polyfill: false,
                    regenerator: true
                }]
            ],
        },
        sass: {
            options: {
                includePaths: [],
                precision: 15
            },
            mode: 'native',
            sourceMapEmbed: true,
            debug: 'comments'
        },
        copycat: {
            "fonts/slick-carousel": ["node_modules/slick-carousel/slick/fonts"],
            "img/slick-carousel": ["node_modules/slick-carousel/slick/ajax-loader.gif"],
            "": ["theme/theme_header.tmpl", "theme/theme_body.tmpl", "theme/theme_footer.tmpl"],
        }
    },
    modules: {
        nameCleaner: path => path.replace('', theme_name + '/')
    },
    notifications: false,
    hot: false,
    paths: {
        public: '../',
        watched: [
            'theme',
            'initialize.js',
        ]
    },
    overrides: {
        production: {
            optimize: true,
            sourceMaps: false,
            plugins: {
                autoReload: {
                    enabled: false
                }
            },
            paths: {
                // public: "dist/"
            }
        }
    }
};

我能够实现任何接近的唯一方法是在 joinTo 中使用否定。见下文:

javascripts: {
            joinTo: {
                "theme.js": [
                    /^theme/,
                ],
                "theme_vendor.js": [
                    /^(?!theme|node_modules\/react|node_modules\/react-dom)/,
                ],
            }
        },

其他信息:

"dependencies": {
    "react-click-outside": "^2.2.0",
    "react-image-gallery": "^0.7.15",
    "react-slick": "^0.14.7",
    "slick-carousel": "^1.6.0"
  },
  "devDependencies": {
    "auto-reload-brunch": "^2",
    "babel-brunch": "~6.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.0",
    "babel-preset-react": "~6.22",
    "babel-preset-stage-0": "^6.22.0",
    "brunch": "^2",
    "clean-css-brunch": "^2",
    "copycat-brunch": "^1.1.0",
    "hmr-brunch": "^0.1",
    "redux-devtools": "^3.3.2",
    "redux-devtools-dock-monitor": "^1.1.1",
    "redux-devtools-log-monitor": "^1.2.0",
    "sass-brunch": "^2.10.4",
    "uglify-js-brunch": "^2",
    "isomorphic-fetch": "^2.2.1",
    "react": "^15.4",
    "react-addons-css-transition-group": "^15.4.2",
    "react-dom": "^15.4",
    "react-redux": "~4.3.0",
    "react-router": "^3.0.2",
    "react-router-redux": "^4.0.8",
    "redux": "~3.2.1",
    "redux-form": "^6.6.2",
    "redux-logger": "^3.0.0",
    "redux-saga": "^0.14.3"
  }

我认为你需要这样做:

conventions: {
  vendor: /(^bower_components|node_modules(?!\/react)|vendor)\//
}

另见 docs

此正则表达式不会匹配两个反应节点模块,因此不会包含在您的文件中。