<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MiladRx</title>
    <description>The latest articles on DEV Community by MiladRx (@miladrx).</description>
    <link>https://dev.to/miladrx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1180517%2F87e7a8ba-b017-4286-8ad4-c04724b4e68d.png</url>
      <title>DEV Community: MiladRx</title>
      <link>https://dev.to/miladrx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/miladrx"/>
    <language>en</language>
    <item>
      <title>How to configure and install WebPack and setup a SASS/SCSS transpiler</title>
      <dc:creator>MiladRx</dc:creator>
      <pubDate>Tue, 10 Oct 2023 04:25:08 +0000</pubDate>
      <link>https://dev.to/miladrx/how-to-configure-and-install-webpack-and-setup-a-sassscss-transpiler-10lp</link>
      <guid>https://dev.to/miladrx/how-to-configure-and-install-webpack-and-setup-a-sassscss-transpiler-10lp</guid>
      <description>&lt;p&gt;Lets start out with writing sass --save-dev in the Terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install sass --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run npm install sass --save-dev, you are installing the SASS package as a development dependency. Development dependencies are packages that are only needed during the development process and don't affect the application's functionality in a production &lt;/p&gt;

&lt;p&gt;to automatically set up the required folders and files in your project, you can run the following commands in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir src
mkdir src/scss
mkdir dist
mkdir dist/css
type nul &amp;gt; src/scss/_main.scss
type nul &amp;gt; src/style.scss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands are commonly used when setting up a project structure and initializing the necessary directories and files for development.&lt;/p&gt;

&lt;p&gt;Install the necessary dependencies by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install webpack webpack-cli sass-loader style-loader npm i mini-css-extract-plugin css-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's set up the SASS/SCSS transpiler with watch. Open your package.json file.&lt;/p&gt;

&lt;p&gt;Update the scripts section to include the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "build": "webpack"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script uses the node-sass package to watch the src/scss directory for changes and transpile the SASS/SCSS files to CSS, which are then outputted to the dist/css directory.&lt;/p&gt;

&lt;p&gt;now lets integrate the SASS/SCSS transpilation into a Webpack configuration.&lt;/p&gt;

&lt;p&gt;Create a webpack.config.js file in the root of your project directory.&lt;/p&gt;

&lt;p&gt;Open the webpack.config.js file and add the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  plugins: [ new MiniCssExtractPlugin() ],
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader',
        ],
      },
    ],
  },
  devtool: 'source-map',
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure your SASS/SCSS files are imported in your entry file (src/index.js in this example).&lt;/p&gt;

&lt;p&gt;Make sure you add the following code &lt;/p&gt;

&lt;p&gt;Now, you can run the following command to start both the SASS/SCSS transpiler and Webpack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
