88 <a href =" https://github.com/andreashuber69/async-css-plugin/releases/latest " >
99 <img src="https://img.shields.io/github/release-date/andreashuber69/async-css-plugin.svg" alt="Release Date">
1010 </a >
11- <a href =" https://travis-ci.com/andreashuber69/async-css-plugin " >
12- <img src="https://travis-ci.com/andreashuber69/async-css-plugin.svg?branch=develop " alt="Build">
11+ <a href =" https://travis-ci.com/github/ andreashuber69/async-css-plugin " >
12+ <img src="https://travis-ci.com/andreashuber69/async-css-plugin.svg?branch=master " alt="Build">
1313 </a >
1414 <a href =" https://github.com/andreashuber69/async-css-plugin/issues " >
1515 <img src="https://img.shields.io/github/issues-raw/andreashuber69/async-css-plugin.svg" alt="Issues">
@@ -47,15 +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://webpack.js.org/ ) ** . More specifically,
51- your application must satisfy ** one** of the following conditions:
50+ This plugin is designed for applications that are built using ** [ webpack] ( https://v4. webpack.js.org/ ) ** . More
51+ 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://webpack.js.org/configuration/ ) * .
54+ with * [ webpack.config.js] ( https://v4. webpack.js.org/configuration/ ) * .
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.
62+
5963## Getting Started
6064
6165### Installation
@@ -64,45 +68,70 @@ your application must satisfy **one** of the following conditions:
6468
6569### Configuration
6670
67- ` AsyncCssPlugin ` configuration depends on how your project is set up, please see [ Prerequisites] ( #Prerequisites ) for
71+ ` AsyncCssPlugin ` configuration depends on how your project is set up, please see [ Prerequisites] ( #prerequisites ) for
6872more information.
6973
7074#### webpack.config.js
7175
72- If your project does not yet contain * [ webpack.config.js] ( https://webpack.js.org/configuration/ ) * , please create one in
73- the same folder as * package.json* . Otherwise, please modify accordingly. ` AsyncCssPlugin ` depends on
74- [ HtmlWebpackPlugin] ( https://webpack.js.org/plugins/html-webpack-plugin/ ) , so * webpack.config.js* should minimally look
75- as follows:
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
79+ 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:
82+
83+ ` npm install html-webpack-plugin mini-css-extract-plugin css-loader --save-dev `
84+
85+ Given the configuration recommendations for these plugins with added asynchronous CSS loading your * webpack.config.js*
86+ should minimally look something like this:
7687
7788``` js
78- const HtmlWebpackPlugin = require (' html-webpack-plugin' )
79- const AsyncCssPlugin = require (" async-css-plugin" );
89+ const AsyncCssPlugin = require (" async-css-plugin" ); // Added for async CSS loading
90+ const HtmlWebpackPlugin = require (" html-webpack-plugin" );
91+ const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
8092
8193module .exports = {
94+ entry: __dirname + " /index.js" ,
95+ output: {
96+ path: __dirname + " /dist" ,
97+ filename: " index_bundle.js" ,
98+ },
99+ module: {
100+ rules: [
101+ {
102+ test: / \. css$ / i ,
103+ use: [MiniCssExtractPlugin .loader , " css-loader" ],
104+ },
105+ ],
106+ },
82107 plugins: [
83108 new HtmlWebpackPlugin (),
84- new AsyncCssPlugin ({ /* options */ })
109+ new MiniCssExtractPlugin (),
110+ new AsyncCssPlugin ({ logLevel: " info" }), // Added for async CSS loading
85111 ]
86112};
87113```
88114
89115#### vue.config.js
90116
91- If your ** Vue** project does not yet contain * [ vue.config.js] ( https://cli.vuejs.org/config/ ) * , please create one in the same
92- folder as * package.json* . Otherwise, please adapt accordingly:
117+ If your ** Vue** project does not yet contain * [ vue.config.js] ( https://cli.vuejs.org/config/ ) * , please create one in the
118+ same folder as * package.json* . Otherwise, please adapt accordingly:
93119
94120``` js
95- const AsyncCssPlugin = require (" async-css-plugin" );
121+ const AsyncCssPlugin = require (" async-css-plugin" ); // Added for async CSS loading
122+ const HtmlWebpackPlugin = require (" html-webpack-plugin" );
96123
97124module .exports = {
98125 chainWebpack : config => {
99- config .plugin (" async-css-plugin" ).use (AsyncCssPlugin, [{ /* options */ }]);
100- }
101- }
126+ // Added for async CSS loading
127+ config .plugin (" html-webpack-plugin" ).use (HtmlWebpackPlugin);
128+ config .plugin (" async-css-plugin" ).use (AsyncCssPlugin, [{ logLevel: " info" }]);
129+ },
130+ };
102131```
103132
104- By default, ** Vue** internally already uses [ HtmlWebpackPlugin ] ( https://webpack.js.org/plugins/html-webpack-plugin/ ) , so
105- there should be no need to configure that in * vue.config.js* .
133+ By default, ** Vue** already generates separate * .css * files , so there should be no need to make additional changes in
134+ * vue.config.js* .
106135
107136## Usage
108137
0 commit comments