Rails 6: javascript doesn't compile on production

Viewed 265

I have recently updated from Rails 5 to Rails 6 and now using webpacker.

My first deploy to production worked well, somes script from webpacker are working correctly. I have finally migrated all my old JS to webpacker and it's working pretty well on development, but on production it's not working at all.

My new js isn't compiled at all, I have tried to put some debug on application.js but I can't see anything.

Here is my application.js

/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb

require("@rails/ujs").start()
require("turbolinks").start()
require("trix")
require("@rails/actiontext")


// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
console.log('debug')
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import 'pagy.js.erb'
import "controllers"

my webpack production.js

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()

my webpack environment.js

const { environment } = require('@rails/webpacker')
const erb = require('./loaders/erb')
const customConfig = require('./custom')

environment.config.set('output.filename', '[name].js')
environment.config.merge(customConfig)
environment.config.merge({ devtool: 'none' })
environment.loaders.prepend('erb', erb)
module.exports = environment

and here is my application.html.erb

  <head>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application' %>
    <link href="https://fonts.googleapis.com/css?family=Noto+Sans+KR:300&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
    <link rel="apple-touch-icon" sizes="152x152" href="/faviconapple.png">
    <link rel="canonical" href="<%= yield(:link) %>">
    <%= favicon_link_tag asset_path('favicon.ico') %>
  </head>

Here is what I do when I try to deploy to the production

1. rails assets:clobber
2. rails assets:precompile
3. touch tmp/restart.txt or /etc/init.d/apache2 restart
0 Answers
Related