【问题标题】:Vue.js exclude folders from webpack bundleVue.js 从 webpack 包中排除文件夹
【发布时间】:2020-07-22 03:50:46
【问题描述】:

我遇到了一个关于 webpack 的非常简单的问题。 我有一个使用 vue-cli 创建的简单 Vue.js 应用程序。

我创建了要从捆绑包中排除的文件夹 public/Reports(该文件夹包含子文件夹和 PDF)。

我的项目结构是标准的:

├── dist/
│   └── (I don't want "Reports" folder here)
├── public/
│   ├── index.html
|   ├── Reports (folder that I need during development, it contains subfolders and PDfs)
│   │   └── subfolder1
│   │       └── file1.pdf
│   └── ...
├── src/
│   └── ...
├── .babel.config.js
├── .eslintrc.js
├── package.json
├── prettier.config.js
├── vue.config.js
└── README.md

我尝试排除vue.config.js 中的Reports 文件夹,但它不起作用:

const path = require("path");
const webpack = require("webpack");

module.exports = {
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.pdf$/,
                    exclude: [
                        path.resolve(__dirname, "public/Reports"),
                    ],
                },
            ],
        },
    },
};

我怎样才能排除这个文件夹(和子文件夹)被包含在包中?

【问题讨论】:

标签: vue.js webpack


【解决方案1】:

您需要点击复制插件。

// vue.config.js
module.exports = {
  chainWebpack: (config) => {
    config.plugin("copy").tap(([options]) => {
      options[0].ignore.push("Reports/**");
      return [options];
    });
  },
};

【讨论】:

  • 感谢史蒂夫,它有一个小修复:options[0].ignore.push("Reports/**"); 因为报告文件夹有子文件夹
猜你喜欢
  • 2020-05-05
  • 2018-12-22
  • 2017-10-12
  • 1970-01-01
  • 2017-07-10
  • 2022-10-07
  • 2013-01-05
  • 2020-04-13
  • 1970-01-01
相关资源
最近更新 更多