2017-04-16 92 views
1

我正在構建一個具有多個入口點的應用程序。這是一個插件/側載反應架構。brunch.io conventions.ignored不尊重node_modules

我有一個基本反應的應用程序編譯到app.js和vendor.js就好了。這個問題源於二級項目,這個主題與一些相同的依賴項捆綁在一起。最顯着的反應和反應。我希望能夠使用conventions.ignored指示brunch忽略特定的node_modules及其依賴關係。不管我在conventions中使用哪個正則表達式,我仍然會在theme_vendor.js包中得到反應和反應。請參閱下面的配置:

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" 
    } 

回答

1

我認爲你需要做的是:

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

又見docs

編輯:我改變了答案。這個正則表達式不會匹配兩個反應節點模塊,因此不會包含在您的文件中。

+0

感謝您的建議。這是一個很好的解決方法...但是,我不希望將這些文件複製到公共目錄中,我只是希望它們被忽略。 – Menklab

+0

噢,是我的錯。有了它,如果它們在列表中,它們就會被複制,所以如果它匹配的話。所以,也許你必須構建一個排除它們的RegEx。 –

+0

我更新了我的答案。它現在工作嗎? –