ember.js 如何排除公用文件夹中的图像文件

e0bqpujr  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(170)

public文件夹中,我有两个文件夹hksg,它们有不同的图像文件。
我想要的是,如果我构建hk包,我只从hk文件夹复制图像。
如何在ember-cli中排除sg文件夹?

3hvapo4f

3hvapo4f1#

Ember使用Broccoli.js作为它的构建管道。Broccoli是围绕树的概念构建的。请查看it's documentation以了解详细信息。
您可以使用名为broccoli-funnel的插件从树中排除文件。它需要一个输入节点,该节点可以是作为字符串的目录名,也可以是作为第一个参数的现有broccoli树。应该提供一个配置对象作为第二个参数。应该排除的文件或文件夹可以由该对象上的exclude选项指定。
broccoli树是在ember-cli-build.js的构建过程中创建的。从该文件导出的函数应该返回一个树。默认情况下,它直接返回由app.toTree()创建的树。但您可以在之前使用broccoli-funnel自定义该树。
此差异显示了如何自定义Ember CLI 3.16.0蓝图提供的默认ember-cli-build.js以排除特定文件:

diff --git a/ember-cli-build.js b/ember-cli-build.js
index d690a25..9d072b4 100644
--- a/ember-cli-build.js
+++ b/ember-cli-build.js
@@ -1,6 +1,7 @@
 'use strict';

 const EmberApp = require('ember-cli/lib/broccoli/ember-app');
+const Funnel = require('broccoli-funnel');

 module.exports = function(defaults) {
   let app = new EmberApp(defaults, {
@@ -20,5 +21,7 @@ module.exports = function(defaults) {
   // please specify an object with the list of modules as keys
   // along with the exports of each module as its value.

-  return app.toTree();
+  return new Funnel(app.toTree(), {
+    exclude: ['file-to-exclude'],
+  });
 };

您应该显式地将broccoli-funnel添加到依赖项中,即使它可以作为间接依赖项使用:

// if using npm
npm install -D broccoli-funnel

// if using yarn
yarn add -D broccoli-funnel

Broccoli-funnel不仅支持精确的文件名,还支持正则表达式、全局字符串或函数来定义要排除的文件。请查看它的文档以了解详细信息。

相关问题