Skip to content

Commit

Permalink
feat(css): minify CSS using cssnano
Browse files Browse the repository at this point in the history
  • Loading branch information
djcsdy committed Feb 19, 2019
1 parent d87dea7 commit 3061643
Show file tree
Hide file tree
Showing 4 changed files with 742 additions and 23 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/djc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CleanWebpackPlugin = require("clean-webpack-plugin");
import cssnano = require("cssnano");
import HtmlWebpackPlugin = require("html-webpack-plugin");
import MiniCssExtractPlugin = require("mini-css-extract-plugin");
import {dirname, normalize, resolve, sep} from "path";
Expand Down Expand Up @@ -97,6 +98,7 @@ function WebpackConfig(project: WebpackConfig.Project): (env: any) => Configurat
const cssLoader: RuleSetUse = {
loader: "css-loader",
options: {
importLoaders: mode === "development" ? 1 : 0,
modules: "local",
localIdentName: mode === "development"
? "[local]-[sha256:contenthash:base64:5]"
Expand All @@ -105,6 +107,13 @@ function WebpackConfig(project: WebpackConfig.Project): (env: any) => Configurat
}
};

const postcssLoader: RuleSetUse = {
loader: "postcss-loader",
options: {
plugins: [cssnano]
}
};

const lessLoader: RuleSetUse = {
loader: "less-loader",
options: {
Expand Down Expand Up @@ -134,13 +143,13 @@ function WebpackConfig(project: WebpackConfig.Project): (env: any) => Configurat
test: /\.css$/,
use: mode === "development"
? [styleLoader, cssLoader]
: [MiniCssExtractPlugin.loader, cssLoader]
: [MiniCssExtractPlugin.loader, cssLoader, postcssLoader]
},
{
test: /\.less$/,
use: mode === "development"
? [styleLoader, cssLoader, lessLoader]
: [MiniCssExtractPlugin.loader, cssLoader, lessLoader]
: [MiniCssExtractPlugin.loader, cssLoader, postcssLoader, lessLoader]
},
{
test: /\.(png|jpe?g|gif)$/,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"@softwareventures/tslint-rules": "0.6.4",
"@types/clean-webpack-plugin": "0.1.2",
"@types/cssnano": "^4.0.0",
"@types/html-webpack-plugin": "3.2.0",
"@types/mini-css-extract-plugin": "0.2.0",
"@types/node": "10.12.26",
Expand All @@ -34,11 +35,13 @@
"@softwareventures/tsconfig": "^1.0.0",
"clean-webpack-plugin": "^1.0.0",
"css-loader": "^2.1.0",
"cssnano": "^4.1.10",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"mini-css-extract-plugin": "^0.5.0",
"postcss-loader": "^3.0.0",
"style-loader": "^0.23.1",
"uglifyjs-webpack-plugin": "^2.1.1"
},
Expand Down
Loading

0 comments on commit 3061643

Please sign in to comment.