1

I've got quite some experience in (web) development (Java, ASP.NET and PHP amongst all), and fairly new to React and Node JS.

Although I did multiple tutorials and read multiple articles, I feel like I'm missing some point here and there. Currently I'm working on a React app which implements a nice HTML template I found.

One React tutorial I did used Webpack for building and deploying the app (local). This works nice, does the job of transpiling ES6 (.jsx) and SASS using babel. So far so good :)

My template has an image slider (Owl Carousel), so I installed the react-owl-carousel module. This gave me quite some problems with jQuery (also installed as a module). After several attempts to fix this I decided to move on to another slider module, React Awesome slider.

I used the module as the README.md explained. But upon building it (npm run build), I got an error that the .scss file within react-awesome-slider could not be transpiled. A message like "are you missing a loader".

So I installed sass, node-sass, sass-loader etc etc and configured these in my webpack.config.js. I also noticed the react-awesome-slider module within node-modules contained a webpack.config.js.

Long story so far, sorry, now to the essence of this question.

In what way can the modules installed (like react-awesome-slider) be considered "black boxes"? It doesn't feel logical that all the modules get build when building the main app. The "exclude: /node_modules/," config in webpack.config.js prevents this, not?

So why does the react-awesome-slider give an error about .scss transpiling? I had no .scss rule in my webpack config then.

Will all dependend modules automatically get installed when installing a new module? So when I run "npm i react-awesome-slider --save-dev", will its dependencies also be installed? Or is this not necessary? And do I need to update (webpack) configuration after installing a new module? Or is it really black box and "self-containing"?

Any help would greatly be appreciated!!! Maybe there is a good react-webpack sample app on Github or something like that?

2 Answers 2

0

That also confusing me for a really long time. Here are some answers to your question.

  1. people publish packages to the NPM, so a module your project depends on can be pre-builded or source code, it depends. I have checked react-awesome-slider, it's main field in package.json is dist/index.js, directly import it won't cause an issue because there are no SCSS files.If you follow the CSS module usage instruction you have import react-awesome-slider/src/styles and you will find src/styles.js file import ../styled.scss,so webpack will load it with SCSS loader which you have not configured, that's why an error occurred.

  2. while you install modules, npm will go through its dependency tree, install its dependencies, dependencies' dependencies, until there's no more dependency module to install. before npm 3.0 the node_module folder is tree structure reflects the dependency tree, but it causes problems that many modules relay on the same dependency, npm will download and save too many same files, after version 3.0 it becomes flat(release note here, search flat keyword).

  3. You don't need to update your webpack config after you install a dependency cause webpack build process will handle it with file dependency tree. You have installed a package and import it in your activation code, file there will be handle( with its package.json main field file as an entry), you have installed a package without using it or import it in a dead file(dead file means you cannot find it from webpack entry file), it will be ignored by webpack as it's dead code.

I have too many confuse until I read npm docs. Good luck to you.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this extensive answer Oboo! This for sure gives me new insights! I understand your 1. point about the .scss being referenced and therefor loaded. I was busy trying to find out how I can customize React Awesome Sliders styling. This must be the answer: it is done by customizing and refering the .scss file. I will do some futher reading about the flat keyword.
0

Node modules are build to execute packages.When the are compiled they have proper configuration to handle extensions that are imported in it and when you import something like .scss in your main app then it does not know about that extension then your webpack need rules to include that extensions.
It does exclude node_modules as the are pre-converted pr pre build.
More over webpack is bit tough so developers create CRA Have look at it.

1 Comment

Thx! I already used CRA, its great. Found another nice React-Webpack sample app: github.com/wiziple/react-webpack-example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.