kevin1024/django-npm

Separate prefix for .js and .css

Opened this issue · 3 comments

It would be amazing to have an ability to set NPM_STATIC_FILES_PREFIX per filetype.

Without a doubt, but I think we want to keep this package as simple as possible. Unless you convince me it's a game changer, of course :)

You have a point @raphael-boucher :)
uhmm, i don't know if I have a very strong argument. But one good use I found is to put external libraries in, let's say fontawesome-all.js, static/lib/fontawesome/, then set NPM_STATIC_FILES_PREFIX to lib as well, after running collecstatic, you'll end up with all of your 3rd-party dependencies under <collected_static>/lib which is amazing. But, yeah, it would be even better to have stuff under <collected_static>/lib/<package_name>/js and <collected_static>/lib/<package_name>/css, looks much nice in the templates when you reference the files.

And that can be an optional setting, just an expansion of what is already there, similar to your NPM_FILE_PATTERNS.

Regardless, thanks for your work, guys!

For simple packages which provide only js or only css or both but not images and or fonts this sounds cool, but as general approach is not because other files referenced by the css can be placed at the wrong place.

At the end it is responsibility of the package owner to structure it's package/library. For example Bootstrap has css and js in it's dist folder. Then if you set NPM_STATIC_FILES_PREFIX to vendor you will end up with /static/vendor/bootstrap/dist/css/bootstrap.min.css and similar for the js which is cool.

Probably better improvement will be not only to tell which files the package you want in NPM_FILE_PATTERNS but also how to copy them in your static. Again with the example with the bootstrap I put the following:

NPM_FILE_PATTERNS = {
    'jquery': ['dist/*'],
    'bootstrap': ['dist/*']
}

And I ended up with /static/vendor/jquery/dist/jquery.min.js and I already said about bootstrap, but will be better if we can remove dist somehow from the resulting path.