question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I add versioning on JS and CSS files for a non Laravel app

See original GitHub issue

I know this not an issue, but I can’t figure how (or if it is possible) to version the build assets?

I’m using s standard index.html file in the dist folder, the same directory as the compiled .css and .js files along with mix-manifest.json.

Is there a way to dynamically reference the hashed IDs from the index.html file.

In webpack.mix.js I have:

mix.js('src/js/app.js', 'dist/')
    .sass('src/sass/app.scss', 'dist/')
    .setPublicPath('dist')
    .version()

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JeffreyWaycommented, Sep 22, 2017

Yeah right now, you’d need to load that manifest file and build the URL.

We’re adding an option for file-based versioning soon, so that should solve your problem.

0reactions
artemskycommented, Oct 7, 2017

@jackbarham maybe it will help you for now. I came with this problem far time ago. And created my own helper for non-laravel projects

if (! function_exists('mix')) {
    /**
     * Get the path to a versioned file.
     *
     * @param  string  $path
     * @param  string  $manifestDirectory
     * @return string
     *
     * @throws \Exception
     */
    function mix($path, $manifestDirectory = 'public')
    {

        if (! starts_with($path, '/')) {
            $path = "/{$path}";
        }

        $path = substr($path, 7);

        if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
            $manifestDirectory = "/{$manifestDirectory}";
        }

            if (! file_exists($manifestPath = $_SERVER['DOCUMENT_ROOT'] . $manifestDirectory.'/mix-manifest.json')) {
                throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);

        if (! array_key_exists($path, $manifest)) {
            throw new Exception(
                "Unable to locate Mix file: {$path}. Please check your ".
            'mix-manifest.json output paths and try again.'
        );
        }
        return base_url($manifestDirectory.$manifest[$path]);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I add versioning on JS and CSS files for a non Laravel ...
I'm using s standard index.html file in the dist folder, the same directory as the compiled .css and .js files along with mix ......
Read more >
Auto-Versioning JavaScript and CSS Files in PHP - codeburst
Method 2. This method is more complex and aims to automatically append the version of each JavaScript and CSS file directly to their...
Read more >
Laravel - app.jss and CSS files versionning - Stack Overflow
I am trying to add files versions so that ...
Read more >
Versioning | Laravel Mix Documentation
To assist with long-term caching, Laravel Mix provides the mix.version() method to enable file hashing, such as app.js?id=8e5c48eadbfdd5458ec6 .
Read more >
Cache buster or versioning not working - Laracasts
Mix Laravel cache buster not working, how can I fix this? ... asset to mix and the .css files are not generating random...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found