1.0.0 • Published 3 years ago

append-prepend-loader v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

append-prepend-loader

npm: append-prepend-loader License

Loader for Webpack to append and prepend text to files. The only one that still works.

Installation

  • With npm:
npm i --save-dev append-prepend-loader
  • With yarn:
yarn add --dev append-prepend-loader

Usage

webpack.config.js

module.exports = {
    module: {
        rules: [
            {
                test: /\.js$/,
                use: [
                    {
                        loader: "append-prepend-loader",
                        options: {
                            prepend: "console.log('Top');",
                            append: "console.log('Bottom');",
                        }
                    },
                ]
            },
        ]
    }
};

append and prepend can be one of the T:

  • string
  • function: (content: string, map: SourceMap, meta: Meta) => T
  • asynchronous function: (content: string, map: SourceMap, meta: Meta) => Thenable<T>
  • callback function: (content: string, map: SourceMap, meta: Meta, callback: (error, result) => void) => void
  • Thenable<T>
  • object (which will be converted to json)

    More complex example:

    {
       loader: "append-prepend-loader",
       options: {
           prepend: async (content) => {
               const header = await foo(content);
               return header.trim();
           },
           append: (content, map, meta, callback) => {
               baz(content, footer => callback(null, footer.trim()))
           },
       }
    }