question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do we successfully add CSS and Javascript file from 3rd Party CSS Framework into this Project?

See original GitHub issue

I am relatively new to webpack, so this question may seem newbie…

According to the earlier issue (https://github.com/erikras/react-redux-universal-hot-example/issues/171), and also as I have checked, I can add the css from other front framework ( for example, materialize.css (http://materializecss.com/about.html), or bootstrap.css ) and make it work. I do:

import 'materialize/css/materialize.css';    (in the Client.js)

in the Client.js, with a line " { test: /.css$/, loader: “style-loader!css-loader” }, " added in the loader configuration, and it works out good.

However, when I do as above to include the jquery.js, and materialize.js / bootstrap.js as:

import 'materialize/js/jquery-2.1.1.min.js';    (in the Client.js)
import 'materialize/js/materialize.js';     (in the Client.js)

I get a ton of errors like:

Cannot resolve module ‘jquery’ … Cannot resolve module ‘hammerjs’ …

So anyone could tell me what should I do if I want to use 3rd party framework like Materialize ?

Thank you a lot!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
gabrielmadrugacommented, Dec 8, 2015

As @hank7444 said, you should avoid this:

window.jQuery = require('jquery');
window.$ = require('jquery');

With:

 plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        })
    ]

In your webpack.config.js

8reactions
sunkantcommented, Nov 25, 2015

Currently, I am doing this:

1), In dev.config.js (webpack config):

add loader:

{ test: /\.css$/, loader: "style-loader!css-loader" },

Explanation: why we add this one? To let the webpack to require the CSS file in this project.

2), In client.js:

(npm install materialize-css first and npm install jquery if not installed)

require('materialize-css/dist/css/materialize.css');
window.jQuery = require('jquery');
window.$ = require('jquery');
require('materialize-css/dist/js/materialize.js');
require('materialize-css/js/init.js');

Explanation: why we add these ones? To expose JQuery in the Browser as we normally do this by including the “http:// … … jquery.js” in the index.html. Then, we require the “CSS files”, “Javascript files”, ( note that here we require from the node_modules folder, and this load does not use “babel”, as we config in the Webpack.config.js).

Now the Materialize framework ( or any other 3rd party front-end CSS framework (with js) ) would work.

This solution is hinted by https://github.com/Dogfalo/materialize/issues/1823, helped by @hank7444 @trueter

This is the solution I figure out. Please provide better solutions if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding CSS and JavaScript to an Angular CLI Project
In this article, we explore several “correct” methods of adding CSS and JavaScript into an existing project in a way that will work...
Read more >
Reference third-party CSS styles in SharePoint Framework ...
In the code editor, open the ./src/webparts/jQueryAccordion/JQueryAccordionWebPart.ts file. Just under the last require statement, add ...
Read more >
The Many Ways to Include CSS in JavaScript Applications
Simply Googling “How to add CSS to [insert framework here]” yields a flurry of strongly held beliefs and opinions about how styles should...
Read more >
Adding assets (CSS, JS) to a Drupal theme via *.libraries.yml
In Drupal, stylesheets (CSS) and JavaScript (JS) are loaded through the same system for modules (code) and themes, for everything: asset.
Read more >
Client-side javascript: How to include third party frameworks?
Paths to assets in the css files or javascript files of these libraries are often hardcoded (relative) · less/sass/stylus has to be compiled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found