Havardpede

Havardpede

Heroku missing stylesheet

Hey I am currently lost. I have finally managed to deploy my phoenix project to Heroku. However, it does not manage to digest the assets. or more specifically, the stylesheets.

when calling mix phx.digest locally, it produces the assets as expected. however, this does not seem to be the case when I use heroku. I have the following build packs.

1. https://github.com/HashNuke/heroku-buildpack-elixir
2. https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

in assets/js/app.js:

import css from "../css/app.css";

config/prod.exs:

  cache_static_manifest: "priv/static/cache_manifest.json"

phoenix_static_buildpack.config:

clean_cache=false

# We can change the filename for the compile script with this option
compile="compile"

# We can set the version of Node to use for the app here
node_version=13.8.0

# We can set the version of NPM to use for the app here
npm_version=6.13

# We can set the version of Yarn to use for the app here
yarn_version=1.22.0

# We can set the path to phoenix app. E.g. apps/phoenix_app when in umbrella.
phoenix_relative_path=.

# Remove node and node_modules directory to keep slug size down if it is not needed.
remove_node=false

# We can change path that npm dependencies are in relation to phoenix app. E.g. assets for phoenix 1.3 support.
assets_path=assets

# We can change phoenix mix namespace tasks. E.g. `phoenix` for phoenix < 1.3 support.
phoenix_ex=phx

my webpack:

const path = require("path");
const glob = require("glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const PurgecssPlugin = require("purgecss-webpack-plugin");
const globAll = require("glob-all");

// Custom PurgeCSS extractor for Tailwind that allows special characters in
// class names.
//
// https://github.com/FullHuman/purgecss#extractor
class TailwindExtractor {
  static extract(content) {
    return content.match(/[A-Za-z0-9-_:\/]/g) || [];
  }
}

module.exports = (env, options) => ({
  optimization: {
    minimizer: [
      new OptimizeCSSAssetsPlugin({}),
      new PurgecssPlugin({
        paths: globAll.sync([
          "../lib/myapp_web/templates/**/*.html.eex",
          "../lib/myapp_web/views/**/*.ex",
          "../assets/js/**/*.ts",
          "../assets/js/**/*.js"
        ]),
        extractors: [
          {
            extractor: TailwindExtractor,
            extensions: ["leex", "eex", "ex", "html", "js"]
          }
        ]
      })
    ]
  },
  entry: {
    "./js/app.js": glob.sync("./vendor/**/*.js").concat(["./js/app.js"])
  },
  output: {
    filename: "app.js",
    path: path.resolve(__dirname, "../priv/static/js")
  },
  module: {
    rules: [
      {
        test: /\.ts?$/,
        exclude: /node_modules/,
        use: {
          loader: "ts-loader"
        }
      },
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        // Use the postcss-loader
        use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"]
      }
    ]
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js"]
  },
  plugins: [
    new MiniCssExtractPlugin({
      // create a generatated css file
      filename: '../css/app.css'
    }),
    new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
  ]
});

I am currently using TailwindCSS, and also tried to use TS instead of JS, but mostly undid it, as I thought it might have been the culprit.

Most Liked

outlog

outlog

you really don’t want to do that - you’ll get burned down the line.. do you have parity between dev/prod eg same node version etc..

also what is in you package.json scripts? is the deploy script correct?

Last Post!

Havardpede

Havardpede

I realized I had both tailwindcss and the postcss dependencies within devdependencies rather than dependencies. I dont know if this would make a difference during the build process or not. This is how the package.json is structured:

{
  "version": "1.0.0",
  "repository": {},
  "license": "MIT",
  "scripts": {
    "deploy": "webpack --mode production",
    "watch": "webpack --mode development --watch"
  },
  "dependencies": {
    "@types/node": "^13.7.1",
    "@types/phoenix": "^1.4.3",
    "autoprefixer": "^9.7.4",
    "axios": "^0.19.2",
    "brunch": "^3.0.0",
    "js-yaml": "^3.13.1",
    "phoenix": "file:../deps/phoenix",
    "phoenix_html": "file:../deps/phoenix_html",
    "phoenix_live_view": "file:../deps/phoenix_live_view",
    "postcss-import": "^12.0.1",
    "postcss-loader": "^3.0.0",
    "postcss-purgecss": "^2.0.3",
    "source-map-loader": "^0.2.4",
    "tailwindcss": "^1.2.0",
    "ts-loader": "^6.2.1",
    "typescript": "^3.7.5"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "babel-loader": "^8.0.0",
    "copy-webpack-plugin": "^4.5.0",
    "css-loader": "^2.1.1",
    "glob-all": "^3.1.0",
    "merge": "^1.2.1",
    "mini-css-extract-plugin": "^0.4.0",
    "optimize-css-assets-webpack-plugin": "^4.0.0",
    "purgecss": "^1.4.2",
    "purgecss-webpack-plugin": "^1.6.0",
    "uglifyjs-webpack-plugin": "^1.2.4",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10"
  }
}

Where Next?

Popular in Questions Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement