美文网首页
css 中处理图片

css 中处理图片

作者: visitor009 | 来源:发表于2018-09-24 21:07 被阅读0次

不用mini-css-extract-plugin 就处理不了...

npm i -D file-loader
// webpack.config.js
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const glob = require('glob-all');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PurifyCSSPlugin = require('purifycss-webpack');

module.exports = {
    entry: {
        index: './src/index.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [{ loader: MiniCssExtractPlugin.loader },
                { loader: 'css-loader' },
                ]

            },
            {
                test: /\.(png|jpg|jpef|gif|)$/,
                use: [{
                    loader:'file-loader',
                    options: {
                        outputPath: 'assets/',
                        useRlativePath: true
                    }
                }]
            }
        ]
    },
    plugins: [
        new HTMLWebpackPlugin({
            title: 'css'
        }),
        new MiniCssExtractPlugin({
            filename: "[name].css",
            chunkFilename: "[id].css"
        }),
    ],
    mode: 'development'
};
// base.css

小于某个大小时转base64编码

$_> npm i -D url-loader
// webpack.config.js
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const glob = require('glob-all');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PurifyCSSPlugin = require('purifycss-webpack');

module.exports = {
    entry: {
        index: './src/index.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [{ loader: MiniCssExtractPlugin.loader },
                { loader: 'css-loader' },
                ]

            },
            {
                test: /\.(png|jpg|jpef|gif|)$/,
                use: [{
                    loader:'url-loader',
                    options: {
                        limit: 20480,
                        useRelativePath: true
                    }
                }]
            }
        ]
    },
    plugins: [
        new HTMLWebpackPlugin({
            title: 'css'
        }),
        new MiniCssExtractPlugin({
            filename: "[name].css",
            chunkFilename: "[id].css"
        }),
    ],
    mode: 'development'
};
捕获.JPG

相关文章

网友评论

      本文标题:css 中处理图片

      本文链接:https://www.haomeiwen.com/subject/uabqoftx.html