PHPackages                             davidjegat/jimport-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. davidjegat/jimport-bundle

ActiveSymfony-bundle[Parsing &amp; Serialization](/categories/parsing)

davidjegat/jimport-bundle
=========================

A simple assetic files parser for import javascript files easily.

16PHP

Since Mar 24Pushed 13y agoCompare

[ Source](https://github.com/Djeg/JImportBundle)[ Packagist](https://packagist.org/packages/davidjegat/jimport-bundle)[ RSS](/packages/davidjegat-jimport-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

JImportBundle
=============

[](#jimportbundle)

[![Build Status](https://camo.githubusercontent.com/fa9bd2c2a0964b244df999714087d716cfa80c28e4ee94a5dd4e9d9b0752f7b1/68747470733a2f2f7472617669732d63692e6f72672f64617669646a656761742f4a496d706f727442756e646c652e706e67)](https://travis-ci.org/davidjegat/JImportBundle)

An assetic filter for javascripts file that allow you to import client javascripts easily like that :

```
@import('js/foo.js');
@import('js/rep/bar.js');
@import('js/myDirectory');

// some js code here ...
```

How install it ?
----------------

[](#how-install-it-)

In your `composer.json` add this line :

```
"davidjegat/jimport-bundle": "*"
```

Launch a `composer.phar install` or `composer.phar update`. Finaly, add the bundle into your Symfony2 Kernel :

```
	new DavidJegat\JImportBundle\DavidJegatJImportBundle();
```

It's done ! Jimport is install on your symfony 2.

\## How to use it ?

This first things to do is to register your bundles into your assetic configuration :

```
assetic:
	bundles: [ 'YourBundle' ]
```

Now, with assetic import your only file that you need and add the `jimport` filter :

```
{%
	javascripts
	'bundles/your/js/main.js'
	filter="jimport"
%}

{% endjavascripts %}
```

How does it works ?
-------------------

[](#how-does-it-works-)

Into the `main.js` file, after having register your bundle, add this simple line when you want to import it into your javascript :

```
@import('js/my/lib.js');
```

### Import priority

[](#import-priority)

When you register a bundle into the `assetic.bundles` array key, the `@import` function will look at the `Resources/public` directory of this bundle. If no file is found then the function will parse the next bundle. If definitively no file is found, the function will be replace the `@import` statement by an empty character string.

\## Rocks with Jimport ? Code you own extension !

Jimport is a very simple file parser. It works for javascript files, css files ... any assetic files. You can defined your own JImport function. Let's take an exemple. You need to create a special javascript function that allow you to get a given url from your project. A sort of router ? Let's do it !

\### The first step, FunctionInterface

You can easily create your own jimport function parser by respect this interface :

```
namespace DavidJegat\JImportBundle\Functions;

use DavidJegat\JImportBundle\Parser\Parser;

/**
 * Defined JImport Functions behavior
 *
 * @author David Jegat
 */
interface FunctionInterface
{
	/**
	 * Return your function name
	 *
	 * @return string
	 */
	public function getName();

	/**
	 * Execute the function
	 *
	 * @param array $arguments
	 * @param Parser $parser
	 * @return string, the function relacement
	 */
	public function execute(array $arguments, Parser $parser);
}
```

\### Your own function !?

So, create an object in your bundle and add this code :

```
namespace My\CoolBundle\Jimport;

use DavidJegat\JImportBundle\Functions\FunctionInterface;
use DavidJegat\JImportBundle\Parser\Parser;

class GiveMeTheUrlFunction implements FunctionInterface
{
	/**
	 * @var Router $router, The injected router service
	 * @access private
	 */
	private $router;

	/**
	 * return the function name
	 * @return string
	 */
	public function getName()
	{
		return 'giveMeTheUrl';
	}

	/**
	 * Execute the function
	 * @param array $args, The function arguments
	 * @param Parser $parser, The JImport parser
	 * @return string
	 */
	public function execute(array $args, Parser $parser)
	{
		// just return an absolute url
		return '"'.$this->router->generate('my_road', array(), true).'"';
	}

	/**
	 * constructor, it takes the router service
	 * @param Router $router
	 */
	public function __construct($router)
	{
		$this->router = $router;
	}
}
```

### Register the function

[](#register-the-function)

Into your services.yml add this kind of lines :

```
services:
	my_cool.jimport_function:
		class: 'My\CoolBundle\Jimport\GiveMeTheUrlFunction'
		arguments: [ '@router' ] # inject the router
		tags:
			- { name: 'davidjegat_jimport.function' } # Tag the function !
```

\### Now, let's rock !

Go into your file and used your own function like that for exemple :

```
function getRoad()
{
	return @giveMeTheUrl();
}
```

Caution !
---------

[](#caution-)

You can't use jimport for code dynamical access to the database, or interaction with some datas because, in devellopment your files will be corectly parsed but once the assetic will be dumped the files just be parsed once ! This is bad ! prefer to use AJAX !

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c3eff3833f9fae78b1e9eb04f055428287d6a21067164c8a7d1d932679b742?d=identicon)[davidjegat](/maintainers/davidjegat)

---

Top Contributors

[![Djeg](https://avatars.githubusercontent.com/u/1638230?v=4)](https://github.com/Djeg "Djeg (7 commits)")

### Embed Badge

![Health badge](/badges/davidjegat-jimport-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/davidjegat-jimport-bundle/health.svg)](https://phpackages.com/packages/davidjegat-jimport-bundle)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
