Skip to content

Commit

Permalink
feat: hide console log in preprocess (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrothe authored Jun 1, 2021
1 parent 48a7506 commit 91d3cc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/__tests__/fixtures/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { replace } = require('svelte-preprocess')

console.log('This should not influence the compiler/preprocessor')

module.exports = {
preprocess: [
replace([
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/fixtures/sveltekit.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sveltePreprocess from 'svelte-preprocess'
import adapter from '@sveltejs/adapter-static'

const { replace } = sveltePreprocess

console.log('This should not influence the compiler/preprocessor')

const config = {
kit: {
adapter: adapter
Expand Down
6 changes: 6 additions & 0 deletions src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { preprocess } from 'svelte/compiler'
import { pathToFileURL } from 'url'

const { source, filename, svelteConfig } = process.env

// redefine console.log to hide its output, so it does not interfer with the svelte-compiler
if (console) {
console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = () => {}
}

import(pathToFileURL(svelteConfig)).then(configImport => {
// ESM or CommonJS
const config = configImport.default ? configImport.default : configImport
Expand Down

0 comments on commit 91d3cc6

Please sign in to comment.