[Fixed]-How to avoid having thousands of files in collectstatic with django packages and/or bower?

1๐Ÿ‘

I can share with you our approach: we never put bower_components and other such libraries directly in the static directory. We put them somewhere else and then have a grunt task that copies only the files we need into the static directory.

A basic setup looks something like:

grunt.initConfig({
    // Copy only the stuff we need from bower_components
    copy: {
        all: {
            files: [
                // JS
                {
                    expand: true, flatten: true,
                    // You can be more generic with something like "bower_components/**/*.min.js"
                    src: [
                        "bower_components/bootstrap/dist/js/*.min.js",
                        "bower_components/jquery/*.min.js"
                    ],
                    dest: "static/js/"
                },
                // Same for CSS
            ]
        }
    }
});

This approach has its flaws โ€“ you now have an extra piece of config to maintain on top of your bower.json etc. It will also only help to deal with the files generated by your applications.

In addition to this you can add some --exclude patterns to aws s3 sync to filter out the most obvious fluff. Again there is a caveat here that you may end up causing more problems than you solve if you are not careful what you exclude!

๐Ÿ‘คsolarissmoke

Leave a comment