Phoenix Static Content Does Not Always Load

In my application, I created two java-script files - "app.js" and "vendor.js". These files are created using the "brunch build" correctly in the priv / static / js folder. But when I run my application with the cowboy server, sometimes the files are downloaded in the browser, sometimes I see 404, that is, I get the following error -

GET http://localhost:4000/js/vendor.js 404 (Not Found)
GET http://localhost:4000/js/app.js 

Here is my brunch config:

exports.config = {
    files: {
        javascripts: {
            joinTo: {
                "js/app.js": /^(web\/static\/js)|(web\/static\/js\/*)|(node_modules\/*)/,
                "js/vendor.js": [
                    "web/static/vendor/jquery/dist/jquery.min.js",
                    "web/static/vendor/bootstrap-sass/assets/javascripts/bootstrap.min.js"
                ],
                'js/ignoreThis.js': /^(web\/static\/vendor)/                
            },
            order: {
              before: []
            }
        },
        stylesheets: {
            joinTo: "css/app.css",
            order: {
              before: [],
              after: [
                "web/static/css/app.css"
              ]
            }
        },
        templates: {
            joinTo: "js/app.js"
        }
    },
    conventions: {
        assets: /^(web\/static\/assets)/
    },
    paths: {      
        watched: [
            "web/static",
            "test/static"
        ],        
        public: "priv/static"
    },    
    plugins: {
        babel: {            
            ignore: [/web\/static\/vendor\/js/]
        }
    },
    modules: {
        autoRequire: {
            "js/app.js": ["web/static/js/app"]
        }
    },
    npm: {
        enabled: true
    },
    watcher: {
      usePolling: true
    }
};

Here is my template layout -

<!DOCTYPE html>
<html class="no-js" lang="en">
    <head>
        <!-- Metadata. -->
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="robots" content="follow, index, noarchive" />
        <meta name="viewport" content="initial-scale=1.0, height=device-height, width=device-width" />
        <title><%= @title %></title>
        <base href="/" />

        <!-- Stylesheets and styling. -->
        <link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>" />
    </head>

    <body>        
        <!-- Main Content. -->
        <section class="main">
            <%= render @view_module, @view_template, assigns %>
        </section>        
        <script src="<%= static_path(@conn, "/js/vendor.js") %>"></script>        
        <script src="<%= static_path(@conn, "/js/app.js") %>"></script>
    </body>
</html>
+4
source share

Source: https://habr.com/ru/post/1656807/


All Articles