Skip to content

Commit 722a8e9

Browse files
Merge branch 'release/v1.1.7'
2 parents 81e03eb + 72d4caa commit 722a8e9

18 files changed

+12316
-21845
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.eslintrc.cjs
2+
/dist/

.eslintrc.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// https://github.com/andreashuber69/async-css-plugin#--
2+
module.exports = {
3+
extends: "@andreashuber69",
4+
ignorePatterns: ["/**/*.config.js"],
5+
};

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"davidanson.vscode-markdownlint",
44
"eamodio.gitlens",
55
"eg2.vscode-npm-script",
6-
"ms-vscode.vscode-typescript-tslint-plugin",
6+
"dbaeumer.vscode-eslint",
77
"streetsidesoftware.code-spell-checker",
88
"vector-of-bool.gitflow"
99
]

.vscode/tasks.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ much better perceived responsiveness of your site.
4747

4848
## Prerequisites
4949

50-
This plugin is designed for applications that are built using **[webpack](https://v4.webpack.js.org/)**. More
50+
This plugin is designed for applications that are built using **[webpack](https://webpack.js.org/)**. More
5151
specifically, your application must satisfy **one** of the following conditions:
5252

5353
- Your application is built using **webpack** directly or a framework that allows for the configuration of **webpack**
54-
with *[webpack.config.js](https://v4.webpack.js.org/configuration/)*.
54+
with *[webpack.config.js](https://webpack.js.org/configuration/)*, like e.g. [React](https://reactjs.org/).
5555
- Your application is built using a framework like **[Vue](https://vuejs.org)** that "abstracts away"
5656
*webpack.config.js* but provides a [different way](https://cli.vuejs.org/guide/webpack.html#chaining-advanced) to
5757
modify the **webpack** configuration.
5858

59-
> This version of the plugin has so far only been tested with **webpack** v4 and **Vue** v2. Due to the fact that only a
60-
> very stable API of a plugin is used internally (namely `HtmlWebpackPlugin.getHooks`) it might work with projects that
61-
> are based on later versions of these frameworks but it hasn't been tested yet.
59+
> NOTE: Unfortunately, this plugin does not seem to work with apps based on [Angular](https://angular.io/), see
60+
> [this repo](https://github.com/andreashuber69/async-css-angular-example) for more information. The steps still
61+
> work with **Angular** v14, except for step 9, which can be safely skipped (with v14 css is always extracted, the
62+
> `extractCss` setting is therefore no longer supported).
6263
6364
## Getting Started
6465

@@ -71,22 +72,41 @@ specifically, your application must satisfy **one** of the following conditions:
7172
`AsyncCssPlugin` configuration depends on how your project is set up, please see [Prerequisites](#prerequisites) for
7273
more information.
7374

74-
#### webpack.config.js
75+
#### webpack.config.js for webpack v4 & v5
7576

76-
If your project does not yet contain *[webpack.config.js](https://v4.webpack.js.org/configuration/)*, please create one
77-
in the same folder as *package.json*. Otherwise, please modify accordingly. In order for webpack to generate HTML, you
78-
need to add [html-webpack-plugin](https://v4.webpack.js.org/plugins/html-webpack-plugin/). Moreover, for CSS to be
77+
If your project is configurable with *[webpack.config.js](https://webpack.js.org/configuration/)*, it most likely
78+
already contains this file. For example, if you create a new **React** application with
79+
[create-react-app](https://www.npmjs.com/package/create-react-app) and then run `npm run eject`, you'll find the file
80+
in the *config* folder. In this case you usually only need to add 2 lines of code:
81+
82+
``` js
83+
// ... existing requires ...
84+
const AsyncCssPlugin = require("async-css-plugin"); // added for async CSS loading
85+
86+
module.exports = {
87+
// ... existing options ...
88+
plugins: [
89+
// ... existing plugins ...
90+
new AsyncCssPlugin({ logLevel: "info" }), // added for async CSS loading
91+
],
92+
};
93+
```
94+
95+
If you started with webpack directly, e.g. as described
96+
[here](https://webpack.js.org/guides/getting-started/#basic-setup), then you've probably already created
97+
*webpack.config.js* yourself. In this case, you first need to get webpack to generate HTML, with
98+
[html-webpack-plugin](https://webpack.js.org/plugins/html-webpack-plugin/). Moreover, for CSS to be
7999
generated into separate files it is recommended to use
80-
[mini-css-extract-plugin](https://v4.webpack.js.org/plugins/mini-css-extract-plugin/) and
81-
[css-loader](https://v4.webpack.js.org/loaders/css-loader/). You can add these dependencies as follows:
100+
[mini-css-extract-plugin](https://webpack.js.org/plugins/mini-css-extract-plugin/) and
101+
[css-loader](https://webpack.js.org/loaders/css-loader/). You can add these dependencies as follows:
82102

83103
`npm install html-webpack-plugin mini-css-extract-plugin css-loader --save-dev`
84104

85105
Given the configuration recommendations for these plugins with added asynchronous CSS loading your *webpack.config.js*
86106
should minimally look something like this:
87107

88108
``` js
89-
const AsyncCssPlugin = require("async-css-plugin"); // Added for async CSS loading
109+
const AsyncCssPlugin = require("async-css-plugin");
90110
const HtmlWebpackPlugin = require("html-webpack-plugin");
91111
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
92112

@@ -107,24 +127,21 @@ module.exports = {
107127
plugins: [
108128
new HtmlWebpackPlugin(),
109129
new MiniCssExtractPlugin(),
110-
new AsyncCssPlugin({ logLevel: "info" }), // Added for async CSS loading
111-
]
130+
new AsyncCssPlugin({ logLevel: "info" }),
131+
],
112132
};
113133
```
114134

115-
#### vue.config.js
135+
#### vue.config.js for Vue v3
116136

117-
If your **Vue** project does not yet contain *[vue.config.js](https://cli.vuejs.org/config/)*, please create one in the
137+
If your **Vue** v3 project does not yet contain *[vue.config.js](https://cli.vuejs.org/config/)*, please create one in the
118138
same folder as *package.json*. Otherwise, please adapt accordingly:
119139

120140
``` js
121-
const AsyncCssPlugin = require("async-css-plugin"); // Added for async CSS loading
122-
const HtmlWebpackPlugin = require("html-webpack-plugin");
141+
const AsyncCssPlugin = require("async-css-plugin");
123142

124143
module.exports = {
125144
chainWebpack: config => {
126-
// Added for async CSS loading
127-
config.plugin("html-webpack-plugin").use(HtmlWebpackPlugin);
128145
config.plugin("async-css-plugin").use(AsyncCssPlugin, [{ logLevel: "info" }]);
129146
},
130147
};
@@ -133,6 +150,27 @@ module.exports = {
133150
By default, **Vue** already generates separate *.css* files, so there should be no need to make additional changes in
134151
*vue.config.js*.
135152

153+
#### vue.config.js for Vue v2
154+
155+
If your **Vue** v2 project does not yet contain *[vue.config.js](https://cli.vuejs.org/config/)*, please create one in the
156+
same folder as *package.json*. Otherwise, please adapt accordingly:
157+
158+
``` js
159+
const AsyncCssPlugin = require("async-css-plugin");
160+
const HtmlWebpackPlugin = require("html-webpack-plugin");
161+
162+
module.exports = {
163+
chainWebpack: config => {
164+
config.plugin("html-webpack-plugin").use(HtmlWebpackPlugin);
165+
config.plugin("async-css-plugin").use(AsyncCssPlugin, [{ logLevel: "info" }]);
166+
},
167+
};
168+
```
169+
170+
Note that for **Vue** v2 it seems to be necessary to add `HtmlWebpackPlugin` even though the plugin is already
171+
used internally. In **Vue** v3 however, adding this plugin leads to an error during build, so the config **must** be
172+
different in v2 vs. v3.
173+
136174
## Usage
137175

138176
Once **webpack** is configured as detailed above, stylesheet links in the generated HTML will look similar to the

0 commit comments

Comments
 (0)