src/index.js
function init(userOpts = {}) {
    const opts = Object.assign(
        {
            template: '[hash].[ext][query]',
            preservePath: false,
            hashFunction(contents) {
                return crypto
                    .createHash('sha1')
                    .update(contents)
                    .digest('hex')
                    .substr(0, 16);
            },
            transform(fileMeta) {
                return fileMeta;
            },
            ignore: []
        },
        userOpts
    );

    return (style, result) => {
        if (opts.basePath) {
            if (typeof opts.basePath === 'string') {
                opts.basePath = [path.resolve(opts.basePath)];
            } else {
                opts.basePath = opts.basePath.map(elem => path.resolve(elem));
            }
        } else {
            opts.basePath = [process.cwd()];
        }

        if (opts.dest) {
            opts.dest = path.resolve(opts.dest);
        } else {
            throw new Error('Option `dest` is required in postcss-copy');
        }

        const promises = [];
        style.walkDecls(decl => {
            if (decl.value && decl.value.indexOf('url(') > -1) {
                promises.push(processDecl(result, decl, opts));
            }
        });
        return Promise.all(promises).then(decls =>
            decls.forEach(decl => {
                decl.value = String(decl.value);
            })
        );
    };
}
function init(userOpts = {}) {
    const opts = Object.assign(
        {
            template: '[hash].[ext][query]',
            preservePath: false,
            hashFunction(contents) {
                return crypto
                    .createHash('sha1')
                    .update(contents)
                    .digest('hex')
                    .substr(0, 16);
            },
            transform(fileMeta) {
                return fileMeta;
            },
            ignore: []
        },
        userOpts
    );

    return (style, result) => {
        if (opts.basePath) {
            if (typeof opts.basePath === 'string') {
                opts.basePath = [path.resolve(opts.basePath)];
            } else {
                opts.basePath = opts.basePath.map(elem => path.resolve(elem));
            }
        } else {
            opts.basePath = [process.cwd()];
        }

        if (opts.dest) {
            opts.dest = path.resolve(opts.dest);
        } else {
            throw new Error('Option `dest` is required in postcss-copy');
        }

        const promises = [];
        style.walkDecls(decl => {
            if (decl.value && decl.value.indexOf('url(') > -1) {
                promises.push(processDecl(result, decl, opts));
            }
        });
        return Promise.all(promises).then(decls =>
            decls.forEach(decl => {
                decl.value = String(decl.value);
            })
        );
    };
}
function init ( userOpts = { } ) { const opts = Object . assign ( { template : '[hash].[ext][query]' , preservePath : false , hashFunction ( contents ) { return crypto . createHash ( 'sha1' ) . update ( contents ) . digest ( 'hex' ) . substr ( 0 , 16 ) ; } , transform ( fileMeta ) { return fileMeta ; } , ignore : [ ] } , userOpts ) ; return ( style , result ) => { if ( opts . basePath ) { if ( typeof opts . basePath === 'string' ) { opts . basePath = [ path . resolve ( opts . basePath ) ] ; } else { opts . basePath = opts . basePath . map ( elem => path . resolve ( elem ) ) ; } } else { opts . basePath = [ process . cwd ( ) ] ; } if ( opts . dest ) { opts . dest = path . resolve ( opts . dest ) ; } else { throw new Error ( 'Option `dest` is required in postcss-copy' ) ; } const promises = [ ] ; style . walkDecls ( decl => { if ( decl . value && decl . value . indexOf ( 'url(' ) > - 1 ) { promises . push ( processDecl ( result , decl , opts ) ) ; } } ) ; return Promise . all ( promises ) . then ( decls => decls . forEach ( decl => { decl . value = String ( decl . value ) ; } ) ) ; } ; }
Initialize the postcss-copy plugin
@param  {Object} plugin options
@return {plugin}
Initialize the postcss - copy plugin