Webpack từ A đến Á: Webpack Style Loader (ok)

https://kentrung256.blogspot.com/2020/08/webpack-style-loader.html

Nói chúng để nhúng css vào js thì chỉ cần

'style-loader', 'css-loader'

C:\xampp\htdocs\test\webpack.config.js

var path = require("path");
module.exports = {
  mode: 'development',
  entry: [
    './src/index.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js',
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader']
      }
    ],
  },
};

C:\xampp\htdocs\test\package.json

{
  "name": "webpack",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "start": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.1.0",
    "babel-preset-env": "^1.7.0",
    "css-loader": "^4.3.0",
    "style-loader": "^1.2.1",
    "webpack": "^4.44.2",
    "webpack-cli": "^3.3.12"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/preset-env": "^7.11.5",
    "mini-css-extract-plugin": "^0.11.2"
  }
}

C:\xampp\htdocs\test\src\index.js

import './style.css';

C:\xampp\htdocs\test\src\style.css

ul {
    list-style: none;
}
ul li {
    display: inline-block; margin: 0 10px;
}
ul li a {
    color: #377ab7; text-decoration: none;
}
ul li a:hover {
    color: red;
}

Last updated

Navigation

Lionel

@Copyright 2023