Могу ли я скопировать stati c активы с минификацией (Webpack)? - PullRequest
0 голосов
/ 29 апреля 2020

У меня есть вопрос относительно веб-пакета. У меня есть структура проекта с двумя папками:

Проект:

- sr c

- dist

Я использую webpack-copy-plugin для копирования stati c активов из sr c в dist . Есть ли способ минимизировать и оптимизировать ресурсы при копировании их с помощью webpack-copy-plugin? (css, js, файлы изображений?). Вот мой веб-пакет. js файл ниже.

const HtmlWebpackPlugin = require('html-webpack-plugin'); // Require  html-webpack-plugin plugin
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    entry: [__dirname + "/src/js/entry.js"], // webpack entry point. Module to start building dependency graph
    output: {
        path: __dirname + '/dist', // Folder to store generated bundle
        filename: 'js/bundle.js',  // Name of generated bundle after build
        publicPath: '' // public URL of the output directory when referenced in a browser
    },
    module: {  // where we defined file patterns and their loaders
           rules: [

                {
                    test: /\.js$/,
                    use: 'babel-loader',
                    exclude: [
                        /node_modules/
                    ]
                },
                {
                   test: /\.html/,
                   loader: 'raw-loader'
                },
               {
                   test: /\.s?css$/,
                   use: [//define loader
                       MiniCssExtractPlugin.loader,
                       'css-loader',
                       'sass-loader'
                   ]
               }


            ],

    },
    plugins: [  // Array of plugins to apply to build chunk
        new MiniCssExtractPlugin({
            filename: "style.css"//define fname for compiled css
        }),
        new HtmlWebpackPlugin({
            template: __dirname + "/src/html/index.html",
            inject: 'body'
        }),
        new CopyWebpackPlugin([
            { from: 'src/img/',
                to:"img"
            },
            {from:'src/js/',to:'js',ignore:['entry.js'],transform(content, path) {
                    return content;
                },
                cache: true},
            {from:'src/css/',to:'css',
                transform(content, path) {
                    return content;
                },
            },
            {from:'src/fonts/',to:'fonts'}
        ])



    ],
    devServer: {  // configuration for webpack-dev-server
        contentBase: '/',  //source of static assets
        port: 7700, // port to run dev-server
    }
};
...