nikolis

nikolis

I can't seem to make tailwind css work with my phoenix/react project

Hello all,
I need help with my Tailwind setup. Disclaimer I am a bit of a newbie in the whole asset management thing so to anybody answering please be explain any suggestions, thanks in advance.

So I have created a phoenix project which resides within an umbrella project with sole purpose to serve my react app.

The whole setup seems it is working fine when developing the react app but my lack of understanding in the webpack and in general asset management field is proved to be a burden now that I need to set up tailwind css to React project. I am working with Phoenix 1.5.7 webpack 4.41.5 sass-loader 8.0.2 postcss-loader 4.2.0

My webpack config looks like this

const path = require('path');  
const glob = require('glob');  
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin'); 
  
module.exports = (env, options) => {
  const devMode = options.mode !== 'production';
  
  return {
    optimization: { 
      minimizer: [
        new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
        new OptimizeCSSAssetsPlugin({}) 
      ]
    },
    entry: {
      'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
    },
    output: { 
      filename: '[name].js',   
      path: path.resolve(__dirname, '../priv/static/js'),
      publicPath: '/js/'       
    },
    devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
    module: { 
      rules: [ 
        {
          test: /\.js$/,
          exclude: /node_modules/,        
          use: {
            loader: 'babel-loader'          
          }
        },
        {
          test: /\.[s]?css$/,
          use: [
              MiniCssExtractPlugin.loader,
              'css-loader',
              'postcss-loader',
              'sass-loader',
          ],
        }
      ]
    },
    plugins: [
      new MiniCssExtractPlugin({ filename: '../js/Main.scss' }),
      new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
    ]
    .concat(devMode ? [new HardSourceWebpackPlugin()] : [])
  }
};

My postss.config.js looks like this

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

My tailwind.config.js looks like this

module.exports = {
  content: [
    "./js/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

And all the react code resides within the /js folder.

After all I am trying to use tailwind by importing tailwind components in a file called Main.css

@tailwind base;

@tailwind components;

@tailwind utilities;

which I then import to my react app base file Main.js

I would greatly appreciate if anybody that can even identify what looks off with my set up and direct me to any kind of sources .

First Post!

nikolis

nikolis

Ok, Now I came to realize that there is an apparent answer.

I have changed the UserMeal Schema to this

  schema "history_user_meals" do
    field :meal_datetime, :utc_datetime
    field :title, :string
    field :user_id, :id

    has_many :recipe_user_meals, RecipeUserMeal, on_replace: :delete

    timestamps()
  end

  @doc false
  def changeset(user_meal, attrs) do
    user_meal
    |> cast(attrs, [:title, :meal_datetime])
    |> cast_assoc(:recipe_user_meals, with: &RecipeUserMeal.changeset/2)
    |> validate_required([:title])
  end

So that the cast_assoc only modifies the middle table and I am just using an additional preloading when returning objects.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement