Skip to content

Leave css file #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface Config {
target: string
position?: 'before' | 'after'
removeTarget?: boolean
leaveCssFile?: boolean
}
}
```
Expand All @@ -83,6 +84,7 @@ replace?: {
target: string
position?: 'before' | 'after' // default is 'before'
removeTarget?: boolean // default is false
leaveCssFile?: boolean // default is false
}
```
A config for customizing the location of injection, default will add internal style sheet before the `</head>`
Expand All @@ -92,6 +94,8 @@ A target for adding the internal style sheet
Add internal style sheet `before`/`after` the `target`
#### removeTarget(optional)
if `true`, it will remove the `target` from the output HTML
#### leaveCssFile(optional)
if `true`, it will leave CSS files where they are when inlining

##### example
```html
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ interface Compilation {
interface ReplaceConfig {
position?: 'before' | 'after'
removeTarget?: boolean
target: string
target: string,
leaveCssFile?: boolean
}

interface Config {
Expand Down Expand Up @@ -71,13 +72,16 @@ export default class Plugin
private prepare({ assets }: Compilation) {
const isCSS = is('css');
const isHTML = is('html');
const { replace: replaceConfig = DEFAULT_REPLACE_CONFIG } = this.config;

Object.keys(assets).forEach((fileName) => {
if (isCSS(fileName)) {
const isCurrentFileNeedsToBeInlined = this.filter(fileName);
if (isCurrentFileNeedsToBeInlined) {
this.css[fileName] = assets[fileName].source();
delete assets[fileName];
if (!replaceConfig.leaveCssFile) {
delete assets[fileName]
}
}
} else if (isHTML(fileName)) {
this.html[fileName] = assets[fileName].source();
Expand Down