Exclude node_modules but include one folder

时间:2017-10-29 12:48:18

标签: javascript webpack es6-module-loader

I'm trying to make this emoji-picker工作。但由于它是node_modules中的一个,我无法访问它。我的问题是如何只包含包含表情符号选择器文件的文件夹?这是我的webpack

var path = require('path')

module.exports = {
 entry: './src/js/app.js',
 output: {
  filename: 'build.js',
  path: path.resolve(__dirname, 'dist')
 },
 devServer: {
   contentBase: path.join(__dirname, 'src'),
  port: 4000,
  public: 'localhost:4000'
 },
 devtool: 'cheap-eval-source-map',
 module: {
  rules: [
   {
    // set up standard-loader as a preloader
    enforce: 'pre',
    test: /\.jsx?$/,
    loader: 'standard-loader',
    exclude: /(node_modules)/,
     // how to make this one work? so I can access it
    include: path.resolve(__dirname, '/node_modules/onesignal-emoji-picker/'),
    options: {
      // Emit errors instead of warnings (default = false)
      error: false,
      // enable snazzy output (default = true)
      snazzy: true
    }
  },
  {
    test: /\.css$/,
    loader: 'style-loader!css-loader'
  },
  {
    test: /\.(png|svg|jpg|gif)$/,
    use: [
      'file-loader'
    ]
  }
]
}
}

1 个答案:

答案 0 :(得分:-1)

您提供了两个不会同时匹配的条件(includeexclude)。

来自docs

  

使用多个条件时,所有条件必须匹配。

尝试使用单一条件,例如:

exclude: /node_modules\/(?!.*onesignal-emoji-picker).*$/