如何从Webpack捆绑目录中排除目录? [英] How to exclude directory from getting bundled by Webpack?

查看:43
本文介绍了如何从Webpack捆绑目录中排除目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预期:

当我使用webpack进行构建时,除我的Webpack.config.js设置中的./src/Portfolio目录中的文件外,我的所有JS文件都被捆绑了.

When I build with webpack, all my JS files get bundled except for the files in the ./src/Portfolio directory as per my Webpack.config.js settings.

实际:

Webpack捆绑了所有文件,包括目录中的文件,尽管我在webpack.config.js中提供了设置和其他变体.

Webpack bundles all the files including the ones in the directory despite the settings and other variations i have provided within webpack.config.js.

代码:

Webpack.config.js

Webpack.config.js

const path = require('path');

module.exports = {
  entry: './src/index.js',
  devtool: 'source-map',
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [
          path.resolve(__dirname, './src/Portfolio/')
        ]
      }
    ]
  },
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist')
  }
};

输出:

我如何成功排除./src/Portfolio目录及其目录内容?

How can i successfully exclude the ./src/Portfolio directory and its contents?

推荐答案

根据文件夹结构的外观,您没有为它提供排除的正确目录位置.我认为类似的方法应该可以,但是如果不能,请共享您的文件夹结构.

Depending on what your folder structure looks like it appears you aren't providing it the right directory location to exclude. I would think something like this should work, but if not please share your folder structure.

const path = require('path');

module.exports = {
  entry: './src/index.js',
  devtool: 'source-map',
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [
          './src/Portfolio/'
        ]
      }
    ]
  },
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist')
  }
};

这篇关于如何从Webpack捆绑目录中排除目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆