puli / issues

The Puli issue tracker.
90 stars 5 forks source link

Using puli.json for webpack asset mapping #188

Open robinvdvleuten opened 8 years ago

robinvdvleuten commented 8 years ago

We're using Puli to have some sort of asset mapping of assets produced by Webpack, it looks like this;

{
  "/app/style/js/modernizr.js" : "js/modernizr-4ea3c5271307e0573488.min.js",
  "/app/style/js/scripts.js" : "js/scripts-4ea3c5271307e0573488.min.js"
}

Now I would like to generate an url for the assets in our twig templates like this;

<script src="{{ resource_url('/app/style/js/scripts.min.js') }}">

But the generated url is http://localhost:8888/js/scripts.js where I expected http://localhost:8888/js/scripts-4ea3c5271307e0573488.min.js.

Is such setup possible with Puli?

tgalopin commented 8 years ago

I'm not sure it's possible right now but in the near future, you will be able to use puli.js (it will be put in the Puli organization as soon as it's ready) :) .

@webmozart is it currently possible with the PHP implementation?

ju1ius commented 8 years ago

This issue is not related solely to webpack. The output of the url generator does not take path mappings into account.

$ mkdir -p res/public
$ touch res/public/app_12345.js
$ puli map /res res
$ puli map /res/public/app.js res/public/app_12345.js
$ mkdir web
$ puli server --add localhost web
$ puli publish /res/public localhost
$ puli publish --install
$ tree
├── res
│   └── public
│       └── app_12345.js
└── web
    └── app_12345.js --> ../res/public/app_12345.js
$repository->get('/res/public/app.js')->getFilesystemPath();
// returns "/path/to/res/public/app_12345.js"
$urlGenerator->generateUrl('/res/public/app.js');
// returns "/app.js" instead of "/app_12345.js"
webmozart commented 8 years ago

This is currently not possible, as you found out. We should add a possibility to maintain the original file name when installing assets.