css minification with cssnano
This commit is contained in:
parent
4458e677ee
commit
aaf01c5f21
15
notes.md
15
notes.md
|
@ -20,6 +20,10 @@ Requirements
|
|||
* live server with hmr
|
||||
* clean dist directories
|
||||
|
||||
## NOT INCLUDED
|
||||
* code splitting
|
||||
|
||||
|
||||
#### html
|
||||
|
||||
* html-webpack-plugin - automatically create index.html or use a template file
|
||||
|
@ -47,18 +51,17 @@ Requirements
|
|||
* postcss-import
|
||||
* postcss-mixins
|
||||
* postcss-functions
|
||||
* cssnano-webpack-plugin
|
||||
* stylelint
|
||||
* stylelint-webpack-plugin
|
||||
* cssnano
|
||||
|
||||
#### other
|
||||
|
||||
* webpack-dev-server
|
||||
* clean-webpack-plugin
|
||||
|
||||
|
||||
#### live server
|
||||
|
||||
* webpack-dev-server
|
||||
|
||||
|
||||
|
||||
|
@ -71,7 +74,7 @@ with
|
|||
`"private": "true"`
|
||||
|
||||
|
||||
## Usage Notes
|
||||
## Notes
|
||||
|
||||
Asset management:
|
||||
|
||||
|
@ -97,3 +100,7 @@ If we don't want the loader to treat it as a local file we can use (in webpack.c
|
|||
types - asset/resource (file-loader), asset/inline (url-loader), asset/source (raw-loader), asset (url-loader)
|
||||
for `asset` default size is 8kb. - can configure see
|
||||
[docs](https://webpack.js.org/guides/asset-modules/).
|
||||
|
||||
## Environment variables
|
||||
|
||||
to use environment variables, must change module.exports to use a function.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,13 +6,14 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "webpack serve",
|
||||
"build": "webpack"
|
||||
"build": "webpack --env production"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"css-loader": "^5.0.1",
|
||||
"cssnano-webpack-plugin": "^1.0.3",
|
||||
"html-webpack-plugin": "^4.5.0",
|
||||
"mini-css-extract-plugin": "^1.3.3",
|
||||
"postcss": "^8.2.2",
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const CssnanoPlugin = require ('cssnano-webpack-plugin');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
mode: 'development',
|
||||
module.exports = env => {
|
||||
console.log(env);
|
||||
|
||||
return {
|
||||
mode: env.production ? 'production' : 'development',
|
||||
target: 'web',
|
||||
entry: './src/js/index.js',
|
||||
output: {
|
||||
filename: '[name].bundle.js',
|
||||
filename: env.production ? '[name].[contenthash].bundle.js' : '[name].bundle.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
},
|
||||
devtool: 'inline-source-map',
|
||||
devtool: env.production ? 'cheap-source-map' : 'inline-source-map',
|
||||
devServer: {
|
||||
contentBase: './dist',
|
||||
hot: true,
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin(),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: env.production ? '[name].[contenthash].css' : '[name].css',
|
||||
}),
|
||||
new CleanWebpackPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'src/html/index.html'
|
||||
|
@ -26,6 +33,7 @@ module.exports = {
|
|||
rules: [
|
||||
{
|
||||
test: /\.inline\.css$/i,
|
||||
include: path.resolve(__dirname, 'src/css'),
|
||||
use: [
|
||||
{
|
||||
loader: 'style-loader',
|
||||
|
@ -54,13 +62,23 @@ module.exports = {
|
|||
},
|
||||
{
|
||||
test: /\.css$/i,
|
||||
include: path.resolve(__dirname, 'src/css'),
|
||||
exclude: /\.inline\.css$/i,
|
||||
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
|
||||
},
|
||||
{
|
||||
test: /.(png|svg|jpg|jpeg|gif)$/i,
|
||||
include: path.resolve(__dirname, 'src'),
|
||||
type: 'asset',
|
||||
},
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new CssnanoPlugin({
|
||||
sourceMap: true,
|
||||
})
|
||||
],
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue