Verskeie bundels style in 'n uitleg in Webpack

Gestel nou dat ons verskeie insnydingspunte het wat saamgestel word in hul eie bundels. Laat na elke insnydingspunt hul eie CSS-lêers gekoppel wees. Soos jy reeds weet, in hierdie geval sal daar vir elke insnydingspunt 'n eie CSS-bundel wees. Webpack sal elke een van hierdie bundels outomaties aansluit.

Kom ons toets dit in die praktyk. Laat ons style na die eerste insnydingspunt koppel:

src/test1.jsimport './styles1-1.css';
import './styles1-2.css';

Laat ons style na die tweede insnydingspunt koppel:

src/test2.jsimport './styles2-1.css';
import './styles2-2.css';

Laat ons die instellings uitvoer:

webpack.config.jsexport default {
  context: path.resolve( 'src'),
  entry: {
    test1: './test1.js',
    test2: './test2.js'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve('dist'),
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].[contenthash].css'
    }),
    new HtmlWebpackPlugin(),
  ],
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [MiniCssExtractPlugin.loader, 'css-loader'],
      },
    ],
  },
};

As gevolg sal die uitleglêer die volgende voorkoms hê:

dist/index.html<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <script defer src="test1.18e856b0da2f7862ab19.js"></script>
    <script defer src="test2.d12ade182c2989b4efa8.js"></script>
    <link href="test1.398db7afe3b52e94bb25.css" rel="stylesheet">
    <link href="test2.1d12c304c284a752cb9a.css" rel="stylesheet">
  </head>
  <body>
    
  </body>
</html>
Задание 1

Maak drie insnydingspunte. Na elke punt, koppel drie CSS-lêers. Voer die bundeling uit. Maak seker dat al die bundels outomaties aangesluit word.