0.1.0 • Published 7 years ago

webpack-plugin-asset-extractor v0.1.0

Weekly downloads
3
License
MIT
Repository
gitlab
Last release
7 years ago

webpack-plugin-asset-extractor

This small webpack plugin allows you to set custom public paths for your assets as well as output paths. Main difference to file-loader is that outputPath and publicPath don't affect each other.

Usage

const AssetExtractor = require('webpack-plugin-asset-extractor');

const imageExtractor = new AssetExtractor({
    manifest: 'assets.json'
});

module.exports = {
    // ...
    module: {
        rules: [
            // ...
            {
                test: /\.(gif|png|jpe?g|svg)$/i,
                use: [
                    imageExtractor.loader({
                        hash:'sha512',
                        digest:'hex',
                        name: '[hash].[ext]',
                        publicPath: '/assets/images/'
                    }),
                    {
                        loader: 'image-webpack-loader',
                        options: {
                            // ...
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        // ...
        imageExtractor
    ]
};

Plugin Options

NameTypeDefaultDescription
manifestStringasset-manifest.jsonConfigure a custom filename with generated assets map filename to url

Loader Options

NameTypeDefaultDescription
nameString or Function[hash].[ext]Configure a custom filename template for your file
contextStringthis.options.contextConfigure a custom file context, defaults to webpack.config.js context
publicPathString or Function/Configure a custom public path for your files
outputPathString or Function'undefined'Configure a custom output path for your files (within context)