Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyhopp/prepend-directive
Prepend a directive to the top of a file
https://github.com/tyhopp/prepend-directive
Last synced: 15 days ago
JSON representation
Prepend a directive to the top of a file
- Host: GitHub
- URL: https://github.com/tyhopp/prepend-directive
- Owner: tyhopp
- License: mit
- Created: 2022-08-26T09:56:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-26T11:09:43.000Z (about 2 years ago)
- Last Synced: 2024-11-07T00:43:50.859Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# prepend-directive
Prepend a directive to the top of a file.
Useful as a [post build script](https://docs.npmjs.com/cli/v8/using-npm/scripts#pre--post-scripts) if your build tool (e.g. [microbundle](https://github.com/developit/microbundle)) strips comments and does not allow you to configure the behavior conditionally.
## CLI interface
```shell
npx prepend-directive@latest --directive=\"use strict\" --files=file-a.js,file-b.js
```## Node CJS interface
```js
const prependDirective = require(`prepend-directive`);prependDirective({
directive: `use strict`,
files: [`file-a.js`, `file-b.js`],
cwd: __dirname, // Optional
});
```### Before
file-a.js:
```js
const a = () => `a`;
```file-b.js:
```js
const b = () => `b`;
```### After
file-a.js:
```js
"use strict"
const a = () => `a`;
```file-b.js:
```js
"use strict"
const b = () => `b`;
```