append-prepend-loader
v1.0.0
Published
Loader for Webpack to append and prepend text to files.
Downloads
800
Maintainers
Readme
append-prepend-loader
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()))
},
}
}