Ember CLI Funnel - File Exclusion
`ember-cli-funnel` is an Ember CLI addon designed to exclude specific files or directories from an Ember application's build output. It integrates directly into the `ember-cli-build.js` file, allowing developers to define exclusion patterns using glob syntax within the `EmberApp` configuration. The current stable version, 0.6.1, suggests it's still in a pre-1.0 development phase, implying that its API might not be fully stable, though the core functionality of file funnelling via Broccoli is well-established. Its release cadence appears to be driven by contributions and maintenance, as indicated by a recent dependency update in September 2023 despite the low version number. Key differentiators include its straightforward configuration within the standard Ember build process and its ability to dynamically exclude files based on environment variables or Git branch information, providing fine-grained control over the final build artifact size and content for different deployment targets.
Common errors
-
Error: Cannot find module 'ember-cli-funnel'
cause Attempting to `require` or `import` `ember-cli-funnel` directly into an application JavaScript file or even `ember-cli-build.js`.fix`ember-cli-funnel` is an Ember CLI addon that extends the `EmberApp` build options. It is not directly imported into JavaScript files. Ensure it is listed in your `package.json` and that `ember install ember-cli-funnel` has been run. -
My files aren't being excluded in development! (or other non-production environments)
cause The `funnel.enabled` option defaults to `true` only in the production environment to optimize development build times.fixTo apply file exclusions in development or other environments, you must explicitly set `enabled: true` in your `ember-cli-build.js` configuration: `funnel: { enabled: true, exclude: [...] }`. -
Build fails or includes unexpected files after upgrading Ember CLI or Node.js versions.
cause The package, being pre-1.0 and supporting older Node.js engines (`6.* || 8.* || >= 10.*`), may have underlying Broccoli dependencies or integration mechanisms with `EmberApp` that are not fully compatible with newer Ember CLI or Node.js versions without updates.fixCheck the `ember-cli-funnel` GitHub issues and pull requests for any known compatibility issues or updates required for your specific Ember CLI and Node.js versions. Consider using `ember try:each` to test against multiple Ember versions to identify the breaking point.
Warnings
- gotcha The `enabled` option for `funnel` defaults to `true` only in `production` environments. If you intend to use file exclusion in `development`, `test`, or other non-production environments, you must explicitly set `enabled: true` in your `ember-cli-build.js` configuration.
- breaking As a pre-1.0 release (version 0.6.1), the API and configuration options for `ember-cli-funnel` may be subject to backward-incompatible changes in future minor or patch releases, although no specific breaking changes are documented in the provided README. Developers should be cautious when upgrading within the 0.x range.
- gotcha Incorrectly defined glob patterns in the `exclude` array can lead to unexpected files being included or excluded, potentially causing runtime errors, build failures, or bloating the build output. Paths are typically relative to the project root or the `addon-tree-output` for files originating from other addons.
Install
-
npm install ember-cli-funnel -
yarn add ember-cli-funnel -
pnpm add ember-cli-funnel
Imports
- EmberApp
import EmberApp from 'ember-cli/lib/broccoli/ember-app';
const EmberApp = require('ember-cli/lib/broccoli/ember-app'); - funnel (configuration option)
import funnel from 'ember-cli-funnel';
let app = new EmberApp(defaults, { funnel: { exclude: ['some/path/**/*'] } }); - getRepoInfo (from git-repo-info)
import getRepoInfo from 'git-repo-info';
let getRepoInfo = require('git-repo-info');
Quickstart
// ember-cli-build.js
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const path = require('path');
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Configure ember-cli-funnel to exclude specific files from the build
funnel: {
// Array of glob patterns for files/directories to exclude
exclude: [
// Exclude an entire route folder named 'style-guide' from the app's output
`${defaults.project.pkg.name}/routes/style-guide/**/*`,
// Exclude SCSS files from a specific addon's tree output
'addon-tree-output/some-addon/styles/**/*.scss'
],
// The 'enabled' option defaults to true only in production.
// Explicitly enable it for other environments if needed.
enabled: process.env.EMBER_ENV === 'development' || process.env.EMBER_ENV === 'production'
}
});
// Return the final Broccoli tree for the build process
return app.toTree();
};