Skip to content

Commit 2d777cb

Browse files
committed
css and sass loader added
1 parent 77212ca commit 2d777cb

File tree

6 files changed

+780
-32
lines changed

6 files changed

+780
-32
lines changed

config/webpack.dev.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
22
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
34
const paths = require('./paths');
45

56
module.exports = {
@@ -19,6 +20,18 @@ module.exports = {
1920
test: /(.js|.jsx)/,
2021
exclude: /(node_modules|bower_components)/,
2122
use: 'babel-loader',
23+
},
24+
{
25+
test: /\.s[ac]ss$/i,
26+
use: [
27+
'style-loader',
28+
'css-loader',
29+
'sass-loader',
30+
],
31+
},
32+
{
33+
test: /\.css$/i,
34+
use: ['style-loader', 'css-loader'],
2235
}
2336
]
2437
},
@@ -28,7 +41,14 @@ module.exports = {
2841
hash: true,
2942
title: 'Boilerplate',
3043
}),
44+
new MiniCssExtractPlugin({
45+
filename: '[name].css',
46+
chunkFilename: '[id].css'
47+
})
3148
],
49+
resolve: {
50+
extensions: ['.js', 'jsx', '.scss', '.css']
51+
},
3252
devServer: {
3353
contentBase: paths.output,
3454
port: 9000,

config/webpack.prod.config.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
22
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
34
const HtmlWebpackPlugin = require('html-webpack-plugin');
45
const paths = require('./paths');
56

@@ -19,6 +20,18 @@ module.exports = {
1920
test: /(.js|.jsx)/,
2021
exclude: /(node_modules|bower_components)/,
2122
use: 'babel-loader',
23+
},
24+
{
25+
test: /\.s[ac]ss$/i,
26+
use: [
27+
'style-loader',
28+
'css-loader',
29+
'sass-loader',
30+
],
31+
},
32+
{
33+
test: /\.css$/i,
34+
use: ['style-loader', 'css-loader'],
2235
}
2336
]
2437
},
@@ -33,5 +46,12 @@ module.exports = {
3346
analyzerMode: 'static',
3447
defaultSizes: 'gzip'
3548
}),
36-
]
49+
new MiniCssExtractPlugin({
50+
filename: '[name].[hash].css',
51+
chunkFilename: '[id].[hash].css'
52+
})
53+
],
54+
resolve: {
55+
extensions: ['.js', 'jsx', '.scss', '.css']
56+
},
3757
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@testing-library/jest-dom": "^5.5.0",
3636
"@testing-library/react": "^10.0.2",
3737
"clean-webpack-plugin": "^3.0.0",
38+
"css-loader": "^3.5.2",
3839
"eslint": "^6.8.0",
3940
"eslint-config-airbnb": "^18.1.0",
4041
"eslint-plugin-import": "^2.20.2",
@@ -43,6 +44,10 @@
4344
"eslint-plugin-react-hooks": "^2.5.1",
4445
"html-webpack-plugin": "^4.0.4",
4546
"jest": "^25.3.0",
47+
"mini-css-extract-plugin": "^0.9.0",
48+
"node-sass": "^4.13.1",
49+
"sass-loader": "^8.0.2",
50+
"style-loader": "^1.1.3",
4651
"webpack-bundle-analyzer": "^3.6.1",
4752
"webpack-dev-server": "^3.10.3"
4853
}

src/app.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
2+
import './app.scss';
23

34
export default function App() {
45
return (
5-
<div>Welcome to React Boilerplate!</div>
6+
<div className="App--Container">Welcome to React Boilerplate!</div>
67
);
78
}

src/app.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$bg-color: grey;
2+
$txt-color: white;
3+
4+
.App--Container {
5+
display: flex;
6+
flex: 1;
7+
background: $bg-color;
8+
color: $txt-color;
9+
}

0 commit comments

Comments
 (0)