twan

twan

How to install bootstrap in my project?

Showing Posts 1 to 7

easco

easco

In Phoenix 1.4 the bundler used for JavaScript and CSS assets is Webpack. To integrate Bootstrap into your project, you should look for instructions on installing Bootstrap through Webpack:

The Webpack configuration and sources are found in the assets folder.

twan

twan OP

Sorry.Wrong delete.
Hi @easco , Thanks.
Now i using npm to install jquery-confirm.js and i have to import it in my app.js.
but how to using or import that jquery-confirm.css style to my project.

sweeneydavidj

sweeneydavidj

Hi,
you can import it at the top of your app.css
for example in mine I have…
@import "./bootstrap.min.css";

twan

twan OP

Hi, Thanks.
i need copy out jquery-confirm css from node_modules to my css folder and import in my app.css files?
that css in folder node_modules/jquery-confirm/css/jquery-confirm.css.

kokolegorille

kokolegorille

You can reference the relative path too… like this

@import '../node_modules/bootstrap/scss/bootstrap';
@import '../node_modules/font-awesome/css/font-awesome.css';

Please check your path correspond…

At the end of the process, all css are merged into one file by MiniCssExtractPlugin.

lurnid

lurnid

This is how I got Bootstrap 4.3 installed in Phoenix 1.4:

  • In the project’s /assets directory:
$ npm i -D bootstrap
$ npm install --save jquery popper.js
  • Add this line to your application’s app.js:
import 'bootstrap’;
  • Add a scss folder under the /assets folder.
  • In the scss folder, create a file called _custom.scss for bootstrap settings overrides.
  • Create a file called app.scss in that folder and put these lines in it:
@import "../node_modules/bootstrap/scss/bootstrap”; (or you can import individual components)
@import "custom";
  • For Bootstrap to compile, make sure you install and use the required loaders: sass-loader, postcss-loader with Autoprefixer. With minimal setup, your webpack config should include this rule or similar:
...
{
  test: /\.(scss)$/,
  use: [{
    loader: 'style-loader', // inject CSS to page
  }, {
    loader: 'css-loader', // translates CSS into CommonJS modules
  }, {
    loader: 'postcss-loader', // Run postcss actions
    options: {
      plugins: function () { // postcss plugins, can be exported to postcss.config.js
        return [
          require('autoprefixer')
        ];
      }
    }
  }, {
    loader: 'sass-loader' // compiles Sass to CSS
  }]
},
…
  • Add this line to your config/dev.exs so that the contents of the assets/scss folder you created are watched while you’re developing so that changes are compiled and loaded into the assets/css folder

  • Now if you fire up your phx.server and edit the sass files in the assets/scss folder, the page should refresh with the changes compiled into the relevant file(s) in the assets/css folder

lurnid

lurnid

@import "…/node_modules/bootstrap/scss/bootstrap”; (or you can import individual components) @import “custom”;

I mixed up the order of these lines. They should be in reverse order:

@import "custom";
@import "../node_modules/bootstrap/scss/bootstrap”; (or you can import individual components)

I also realise that I forgot to add the code related to the penultimate bullet point. These are the lines that should be added to your config/dev.exs (assuming you have sass installed):

watchers: [
  ...
  sass: [
    "--watch",
    "assets/scss:assets/css"
  ]
  ...
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews