Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
fix: #34
Browse files Browse the repository at this point in the history
The plugin now only performes a rewrite on `.html`, `.css`, `.js` and `*.map` files
  • Loading branch information
samrith-s committed Mar 13, 2021
1 parent 5122851 commit c9b1a17
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { readFile, writeFileSync } from 'fs';
import * as path from 'path';
import moveFile from 'move-file';
import chalk from 'chalk';
import isImage from 'is-image';

import { ConfigProvider } from './providers/Config';
import { AssetsGraphMap, AssetGraph } from './AssetMap';
Expand Down Expand Up @@ -44,7 +43,8 @@ export class FileManager extends ConfigProvider {
}

private rewriteAsset(asset: AssetGraph): void {
if (!isImage(asset.source)) {
if (this.isWriteable(asset.source)) {
console.log('asset', asset.source);
readFile(asset.source, (error, contents) => {
if (error) {
throw error;
Expand All @@ -60,6 +60,11 @@ export class FileManager extends ConfigProvider {
}
}

private isWriteable(source: string) {
const extension = path.extname(source);
return /(js|css|html|map)$/.test(extension);
}

private async moveAsset(asset: AssetGraph): Promise<void> {
if (asset.destination) {
await moveFile(asset.source, asset.destination);
Expand Down

0 comments on commit c9b1a17

Please sign in to comment.