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.

Documentation about customizing javascript load on the page using NPM is missing

See original GitHub issue

I tried to find a way to combine those 3 references to js files existing in html page, and it looks like there is no such documentation. Beside this, I think every project uses some extra javascript files. In order to have one single reference in html I need a way to compile all the neccessary javascript in one single file. I also need to be able to cusomize the content of the javascript library thru NPM, because I think this is the point of installing the source code with NPM.

I tried unsuccessfully to compile the three references together. It seems that (correct me if I’m wrong) the materialize.js library does not resolve its jQuery dependency internally, and for this reason the three files only see their components when they are loaded on the same file.

I think it is easy to compile a file that only includes the components selected from node_modules, but there is no documentation anywhere for this too, and as I have seen there are many people looking for this documentation. Instead, I think the result custom.js will have the same compilation problem with the other 2 files, jQuery and init.js.

So the question is: where or when will we be able to have the documentation I mentioned above?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pwcreativecommented, Oct 3, 2019

I actually already answered this in another post but it has zero response:

https://github.com/Dogfalo/materialize/issues/6248

  1. Create a folder on your desktop called materialize-js-compiler

  2. Open terminal, cd into this folder, and run the following commands:

git clone https://github.com/Dogfalo/materialize cd materialize npm install npm install -g grunt-cli

This clones the latest materialize release, moves the terminal into it, loads node modules, and as @SorinGFS pointed out, installs the grunt cli globally.

  1. Open the Gruntfile and comment out any unnecessary components on lines 192-221. Bear in mind that some components rely on others, and some are needed by default. I use this compiler to generate the js file for each project I work on, so comment and uncomment as I move from project to project.

  2. If you want to include external js, create a new folders inside materialize-js-compiler > materialize and pop any scripts in there. I use the Startup theme and Slick, so all those scripts go in here. Add these as new lines after line 222:

       'startup/TweenMax.min.js',
       'startup/ScrollMagic.min.js',
       'startup/animation.gsap.min.js',
       'startup/startup.js',
       'slick/slick.min.js'
    
  3. Add a new task right at the end:

grunt.registerTask(‘ugly’, [‘concat:temp’, ‘configureBabel’, ‘babel:bin’, ‘clean:temp’, ‘uglify’]);

Now, if you run ‘grunt ugly’ from terminal, you’ll get a nice new materialize.min.js file in the bin folder - containing just the components you selected and the external scripts.

There will be a neater way to do this but it was the first way I got it to work so I just stick with it. Hope it helps.

0reactions
DanielRufcommented, Oct 3, 2019

he said that better documentation is required.

PRs are always very welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common errors | npm Docs
Possible temporary npm registry glitch, or corrupted local server cache. Run npm cache clean and/or try again later. · This can be caused...
Read more >
npm can't find package.json - Stack Overflow
Go inside the project folder and check whether the package.json file does exist. If you are creating the project using Visual Studio Angular...
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
Tutorial: Create a Node.js and Express app in Visual Studio
You can work with other development tools, because the project file doesn't make custom changes to the Node.js project source. The npm node...
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
On the first line, foo.js loads the module circle.js that is in the same directory as ... Then Node.js will not bother looking...
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