Equinoxxx's avatar

Semantic UI Integration

Hello, I would like to use Semantic UI with my Laravel App (5.4) instead of using default Bootstrap. As I know Semantic UI is using LESS and recommended installation is via npm and gulp. https://semantic-ui.com/introduction/getting-started.html

I searched the whole internet, but unfortunately I didn't find any actual and clear guide. What I'm not sure for example is where should I store my Semantic UI files and how to use it properly with Laravel Elixir and my custom styles etc...

If there is someone who has any experience with Semantic UI integration into Laravel, I would appreciate some advice. Eventually some "step-by-step" guide for me and everyone else having this trouble.

Thank you! :)

0 likes
14 replies
Yamen's avatar
Yamen
Best Answer
Level 22

okay, I've passed throught this lately and I found that it's less complicated to install semantic-ui-css without the headache of compiling less. So, what I did

1 - In your project directory npm install semantic-ui-css --save-dev.

2 - In webpack.mix.js

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .copy('node_modules/semantic-ui-css/semantic.min.css','public/css/semantic.min.css')
   .copy('node_modules/semantic-ui-css/semantic.min.js','public/js/semantic.min.js');

3 - npm run dev.

4 - Refer to semantic-ui from the master as follow

<link rel="stylesheet" type="text/css" href="{{ asset('css/semantic.min.css') }}">
<script src="{{ asset('js/semantic.min.js') }}"></script>
13 likes
KAII's avatar

Estoy utilizando Laravel 7 y tengo problemas on el paquete de íconos. Alguien sabe como podría solucionarlo?

M@rty's avatar

@Yamen Hi, I understand this is an older thread, but I find myself in a situation where I need to integrate Semantic UI with Laravel 10. Instead of Laravel Mix, Vite is now being used. I'm unsure how to proceed, so any assistance would be greatly appreciated.

1 like
Fredderick's avatar

Hello! Perhaps the answer doesn't come from where you expected, but I've recently been dealing with the integration of Semantic UI and its evil and improved sibling, Fomantic UI, in Laravel projects using recent versions (8, 9, and 10) where Vite is used to compile the app's resources instead of Laravel Mix.

To keep it concise, there are two ways to install these frameworks correctly, the simple method, and the complex one (NOTE: The steps should be the same for both cases, Semantic and Fomantic UI, but for practical and personal purposes, Fomantic UI will be used as the base in the examples):

Initial Setup

For both cases, the first thing you need to do is run npm init from the root folder of your Laravel project to generate the vite.config.js file.

Simple Method (cannot be customized)

  • Once you've generated the Vite file, you need to install Fomantic UI in its precompiled CSS version. To do this, run: npm install fomantic-ui-css.
  • After installing Fomantic, import the resources into your app.css and app.js located in resources/css and resources/js, respectively. In app.css, add: @import "fomantic-ui-css/semantic.min.css"; and in app.js, add: import 'fomantic-ui-css/semantic.min.js';
  • Then, from the main view or layout of the application, you need to call a version of JQuery greater than 3.4 and the resources you just installed through Vite. Place the following code below the <title> tag:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
@vite(['resources/css/app.css', 'resources/js/app.js'])
  • And you're DONE! After doing this, the application should recognize the styles and functionality of Fomantic without any issues.

Complex Method (customizable)

  • For this method, you need to follow some steps listed in the official documentation after generating the Vite file. Execute them in the following order:

    • npm install fomantic-ui
    • cd node_modules/fomantic-ui
    • npx gulp install
  • When you run the last command, an installation wizard will start. Only select the options that best fit your preferences and continue with the following steps (NOTE: It is recommended to select the output folder as resources/fomantic or resources/semantic).

  • After that, you need to modify the package.json file as follows:

{
    ...
    "type": "commonjs",
    ...
}
  • Following that, you need to navigate to the project's root folder in the console and access the output folder of the files created by the installation wizard. Inside this folder, run the command: npx gulp build.

  • Next, you need to import the CSS and JS files into your app.css and app.js, respectively. To do this, go to resources/css and resources/js as needed and add the following:

    • In the CSS file: @import "../semantic/dist/semantic.min.css";
    • In the JS file: import '../semantic/dist/semantic.min';
  • Now, you need to do the same thing as in step number 3 of the simple method, and you're DONE! After doing this, the application should recognize the styles and functionality of Fomantic without any issues.

How to customize with LESS?

To do this, you need to go to the output folder of the installation wizard files and inside /src. There you will find everything you need to customize the Fomantic or Semantic installation you performed. NOTE: After every LESS change, it's necessary to re-run: npx gulp build.

1 like
limsocheat's avatar

Hi, I am new to Laravel, I got an error after following your guide.

I have a fresh laravel installed, after I run npm run dev, I got below error.

npm ERR! Linux 4.9.17-c9
npm ERR! argv "/home/ubuntu/.nvm/versions/node/v6.11.2/bin/node" "/home/ubuntu/.nvm/versions/node/v6.11.2/bin/npm" "run" "development"
npm ERR! node v6.11.2
npm ERR! npm  v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @ development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs 
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/ubuntu/workspace/npm-debug.log

npm ERR! Linux 4.9.17-c9
npm ERR! argv "/home/ubuntu/.nvm/versions/node/v6.11.2/bin/node" "/home/ubuntu/.nvm/versions/node/v6.11.2/bin/npm" "run" "dev"
npm ERR! node v6.11.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script 'npm run development'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run development
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs 
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/ubuntu/workspace/npm-debug.log
Equinoxxx's avatar

Hi, are you running your Laravel installation on Homestead or locally and if yes, what OS are you using?

This is common issue with npm and laravel. Try to manually update npm and node.js and repeat the command. Maybe try removing node_modules folder and repet npm install command.

Yamen's avatar

@limsocheat Make sure you have the latest version of node.js and npm installed.

Assuming you are using linux, to upgrade node and npm just paste this in your terminal

sudo apt upgrade node && sudo npm i -g npm

limsocheat's avatar

Hi, @Equinoxxx and @Yamen ! Thanks for your reply.

I am installing Laravel 5.5 on c9.io cloud IDE. I have followed your suggestion, but still not working.

icey's avatar

You need to run npm install first.

1 like
chenry_meliora's avatar

@icey is correct. You have to do run the npm install command first then do the npm run dev on a fresh install.

ragecub3's avatar
mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .copy('node_modules/semantic-ui-css/semantic.min.css','public/css/semantic.min.css')
   .copy('node_modules/semantic-ui-css/semantic.min.js','public/js/semantic.min.js');

must be like this for Laravel 5.7

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('node_modules/semantic-ui-css/semantic.min.css','public/css/semantic.min.css')
    .copy('node_modules/semantic-ui-css/semantic.min.js','public/js/semantic.min.js');
1 like
ssmulders's avatar

I hope I can save someone the absolute horrendous journey of getting the LESS version to work with Mix (which I eventually did). And ofcourse, right around that moment I had the insight to look for a SASS version and whatdoyouknow - it exists.

Save yourself the trouble and use this package: https://github.com/aniftyco/semantic-ui-sass. It's not the latest version (2.3 instead of 2.4) but if you can miss the 2/3 new features from 2.4, save yourself the headache.

Compile a .scss file in webpack.mix that contains @import "~semantic-ui-sass/semantic-ui"; and you're good to go!

AsnCode's avatar

@SSMULDERS - Hy ssmulders : I made this but how you integrate semantic.min.js and jquery ? semantic-ui-sass is js free ? you dont access to reveal components of dynamic things like this ? thanks

1 like
demilade362's avatar

how do i use it in laravel 10. I think this post is an old one but if you can answer me how do i use it in laravel 10. Thank for answering

1 like

Please or to participate in this conversation.