Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/mini-css-extract-plugin/README.md

    r59329aa re29cc2e  
    7272```
    7373
     74> ⚠️ Note that if you import CSS from your webpack entrypoint or import styles in the [initial](https://webpack.js.org/concepts/under-the-hood/#chunks) chunk, `mini-css-extract-plugin` will not load this CSS into the page. Please use [`html-webpack-plugin`](https://github.com/jantimon/html-webpack-plugin) for automatic generation `link` tags or create `index.html` file with `link` tag.
     75
     76> ⚠️ Source maps works only for `source-map`/`nosources-source-map`/`hidden-nosources-source-map`/`hidden-source-map` values because CSS only supports source maps with the `sourceMappingURL` comment (i.e. `//# sourceMappingURL=style.css.map`). If you need set `devtool` to another value you can enable source maps generation for extracted CSS using [`sourceMap: true`](https://github.com/webpack-contrib/css-loader#sourcemap) for `css-loader`.
     77
    7478## Options
    7579
    7680### Plugin Options
    7781
    78 |                               Name                                |         Type         |                Default                | Description                                                                   |
    79 | :---------------------------------------------------------------: | :------------------: | :-----------------------------------: | :---------------------------------------------------------------------------- |
    80 |                    **[`filename`](#filename)**                    | `{String\|Function}` |             `[name].css`              | This option determines the name of each output CSS file                       |
    81 |               **[`chunkFilename`](#chunkFilename)**               | `{String\|Function}` |          `based on filename`          | This option determines the name of non-entry chunk files                      |
    82 |                 **[`ignoreOrder`](#ignoreOrder)**                 |     `{Boolean}`      |                `false`                | Remove Order Warnings                                                         |
    83 |                      **[`insert`](#insert)**                      | `{String\|Function}` | `document.head.appendChild(linkTag);` | Inserts `<link>` at the given position                                        |
    84 |                  **[`attributes`](#attributes)**                  |      `{Object}`      |                 `{}`                  | Adds custom attributes to tag                                                 |
    85 |                    **[`linkType`](#linkType)**                    | `{String\|Boolean}`  |              `text/css`               | Allows loading asynchronous chunks with a custom link type                    |
    86 | **[`experimentalUseImportModule`](#experimentalUseImportModule)** |     `{Boolean}`      |                `false`                | Use an experimental webpack API to execute modules instead of child compilers |
     82|                               Name                                |         Type         |                Default                | Description                                                                                                                               |
     83| :---------------------------------------------------------------: | :------------------: | :-----------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------- |
     84|                    **[`filename`](#filename)**                    | `{String\|Function}` |             `[name].css`              | This option determines the name of each output CSS file                                                                                   |
     85|               **[`chunkFilename`](#chunkFilename)**               | `{String\|Function}` |          `based on filename`          | This option determines the name of non-entry chunk files                                                                                  |
     86|                 **[`ignoreOrder`](#ignoreOrder)**                 |     `{Boolean}`      |                `false`                | Remove Order Warnings                                                                                                                     |
     87|                      **[`insert`](#insert)**                      | `{String\|Function}` | `document.head.appendChild(linkTag);` | Inserts the `link` tag at the given position for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) CSS chunks |
     88|                  **[`attributes`](#attributes)**                  |      `{Object}`      |                 `{}`                  | Adds custom attributes to the `link` tag for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) CSS chunks     |
     89|                    **[`linkType`](#linkType)**                    | `{String\|Boolean}`  |              `text/css`               | Allows loading asynchronous chunks with a custom link type                                                                                |
     90|                     **[`runtime`](#runtime)**                     |     `{Boolean}`      |                `true`                 | Allows to enable/disable the runtime generation                                                                                           |
     91| **[`experimentalUseImportModule`](#experimentalUseImportModule)** |     `{Boolean}`      |              `undefined`              | Use an experimental webpack API to execute modules instead of child compilers                                                             |
    8792
    8893#### `filename`
     
    118123Type: `String|Function`
    119124Default: `document.head.appendChild(linkTag);`
     125
     126> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
    120127
    121128By default, the `mini-css-extract-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
     
    170177Default: `{}`
    171178
     179> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
     180
    172181If defined, the `mini-css-extract-plugin` will attach given attributes with their values on `<link>` element.
    173182
     
    258267```
    259268
     269#### `runtime`
     270
     271Type: `Boolean`
     272Default: `true`
     273
     274Allows to enable/disable the runtime generation.
     275CSS will be still extracted and can be used for a custom loading methods.
     276For example, you can use [assets-webpack-plugin](https://github.com/ztoben/assets-webpack-plugin) to retreive them then use your own runtime code to download assets when needed.
     277
     278`true` to skip.
     279
     280**webpack.config.js**
     281
     282```js
     283const MiniCssExtractPlugin = require("mini-css-extract-plugin");
     284
     285module.exports = {
     286  plugins: [
     287    new MiniCssExtractPlugin({
     288      runtime: false,
     289    }),
     290  ],
     291  module: {
     292    rules: [
     293      {
     294        test: /\.css$/i,
     295        use: [MiniCssExtractPlugin.loader, "css-loader"],
     296      },
     297    ],
     298  },
     299};
     300```
     301
    260302#### `experimentalUseImportModule`
    261303
    262 Use an experimental webpack API to execute modules instead of child compilers.
    263 
    264 This improves performance and memory usage a lot, but isn't as stable as the normal approach.
     304Type: `Boolean`
     305Default: `undefined`
     306
     307Enabled by default if not explicitly enabled (i.e. `true` and `false` allow you to explicitly control this option) and new API is available (at least webpack `5.52.0` is required).
     308Boolean values are available since version `5.33.2`, but you need to enable `experiments.executeModule` (not required from webpack `5.52.0`).
     309
     310Use a new webpack API to execute modules instead of child compilers.
     311This improves performance and memory usage a lot.
    265312
    266313When combined with `experiments.layers`, this adds a `layer` option to the loader options to specify the layer of the css execution.
    267314
    268 You need to have at least webpack 5.33.2.
    269 
    270 **webpack.config.js**
    271 
    272 ```js
    273 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    274 
    275 module.exports = {
    276   plugins: [
    277     new MiniCssExtractPlugin({
     315**webpack.config.js**
     316
     317```js
     318const MiniCssExtractPlugin = require("mini-css-extract-plugin");
     319
     320module.exports = {
     321  plugins: [
     322    new MiniCssExtractPlugin({
     323      // You don't need this for `>= 5.52.0` due to the fact that this is enabled by default
     324      // Required only for `>= 5.33.2 & <= 5.52.0`
     325      // Not avaliable/unsafe for `<= 5.33.2`
    278326      experimentalUseImportModule: true,
    279327    }),
     
    754802          name: "styles",
    755803          type: "css/mini-extract",
    756           // For webpack@4
    757           // test: /\.css$/,
    758804          chunks: "all",
    759805          enforce: true,
     
    789835const path = require("path");
    790836const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    791 
    792 function recursiveIssuer(m, c) {
    793   const issuer = c.moduleGraph.getIssuer(m);
    794   // For webpack@4 issuer = m.issuer
    795 
    796   if (issuer) {
    797     return recursiveIssuer(issuer, c);
    798   }
    799 
    800   const chunks = c.chunkGraph.getModuleChunks(m);
    801   // For webpack@4 chunks = m._chunks
    802 
    803   for (const chunk of chunks) {
    804     return chunk.name;
    805   }
    806 
    807   return false;
    808 }
    809837
    810838module.exports = {
     
    817845      cacheGroups: {
    818846        fooStyles: {
     847          type: "css/mini-extract",
    819848          name: "styles_foo",
    820           test: (m, c, entry = "foo") =>
    821             m.constructor.name === "CssModule" &&
    822             recursiveIssuer(m, c) === entry,
    823           chunks: "all",
     849          chunks: (chunk) => {
     850            return chunk.name === "foo";
     851          },
    824852          enforce: true,
    825853        },
    826854        barStyles: {
     855          type: "css/mini-extract",
    827856          name: "styles_bar",
    828           test: (m, c, entry = "bar") =>
    829             m.constructor.name === "CssModule" &&
    830             recursiveIssuer(m, c) === entry,
    831           chunks: "all",
     857          chunks: (chunk) => {
     858            return chunk.name === "bar";
     859          },
    832860          enforce: true,
    833861        },
     
    930958  },
    931959};
     960```
     961
     962### Multiple Themes
     963
     964**webpack.config.js**
     965
     966```js
     967const MiniCssExtractPlugin = require("mini-css-extract-plugin");
     968
     969module.exports = {
     970  entry: "./src/index.js",
     971  module: {
     972    rules: [
     973      {
     974        test: /\.s[ac]ss$/i,
     975        oneOf: [
     976          {
     977            resourceQuery: "?dark",
     978            use: [
     979              Self.loader,
     980              "css-loader",
     981              {
     982                loader: "sass-loader",
     983                options: {
     984                  additionalData: `@use 'dark-theme/vars' as vars;`,
     985                },
     986              },
     987            ],
     988          },
     989          {
     990            use: [
     991              Self.loader,
     992              "css-loader",
     993              {
     994                loader: "sass-loader",
     995                options: {
     996                  additionalData: `@use 'light-theme/vars' as vars;`,
     997                },
     998              },
     999            ],
     1000          },
     1001        ],
     1002      },
     1003    ],
     1004  },
     1005  plugins: [
     1006    new Self({
     1007      filename: "[name].css",
     1008      attributes: {
     1009        id: "theme",
     1010      },
     1011    }),
     1012  ],
     1013};
     1014```
     1015
     1016**src/index.js**
     1017
     1018```js
     1019import "./style.scss";
     1020
     1021let theme = "light";
     1022const themes = {};
     1023
     1024themes[theme] = document.querySelector("#theme");
     1025
     1026async function loadTheme(newTheme) {
     1027  // eslint-disable-next-line no-console
     1028  console.log(`CHANGE THEME - ${newTheme}`);
     1029
     1030  const themeElement = document.querySelector("#theme");
     1031
     1032  if (themeElement) {
     1033    themeElement.remove();
     1034  }
     1035
     1036  if (themes[newTheme]) {
     1037    // eslint-disable-next-line no-console
     1038    console.log(`THEME ALREADY LOADED - ${newTheme}`);
     1039
     1040    document.head.appendChild(themes[newTheme]);
     1041
     1042    return;
     1043  }
     1044
     1045  if (newTheme === "dark") {
     1046    // eslint-disable-next-line no-console
     1047    console.log(`LOADING THEME - ${newTheme}`);
     1048
     1049    import(/* webpackChunkName: "dark" */ "./style.scss?dark").then(() => {
     1050      themes[newTheme] = document.querySelector("#theme");
     1051
     1052      // eslint-disable-next-line no-console
     1053      console.log(`LOADED - ${newTheme}`);
     1054    });
     1055  }
     1056}
     1057
     1058document.onclick = () => {
     1059  if (theme === "light") {
     1060    theme = "dark";
     1061  } else {
     1062    theme = "light";
     1063  }
     1064
     1065  loadTheme(theme);
     1066};
     1067```
     1068
     1069**src/dark-theme/\_vars.scss**
     1070
     1071```scss
     1072$background: black;
     1073```
     1074
     1075**src/light-theme/\_vars.scss**
     1076
     1077```scss
     1078$background: white;
     1079```
     1080
     1081**src/styles.scss**
     1082
     1083```scss
     1084body {
     1085  background-color: vars.$background;
     1086}
     1087```
     1088
     1089**public/index.html**
     1090
     1091```html
     1092<!DOCTYPE html>
     1093<html lang="en">
     1094  <head>
     1095    <meta charset="UTF-8" />
     1096    <meta name="viewport" content="width=device-width, initial-scale=1" />
     1097    <title>Document</title>
     1098    <link id="theme" rel="stylesheet" type="text/css" href="./main.css" />
     1099  </head>
     1100  <body>
     1101    <script src="./main.js"></script>
     1102  </body>
     1103</html>
    9321104```
    9331105
Note: See TracChangeset for help on using the changeset viewer.