Skip to content

Instantly share code, notes, and snippets.

@kettanaito
Last active February 9, 2021 17:23
Show Gist options
  • Save kettanaito/c1b7cf1242a03c2e934a21c1e736cc9a to your computer and use it in GitHub Desktop.
Save kettanaito/c1b7cf1242a03c2e934a21c1e736cc9a to your computer and use it in GitHub Desktop.
Webpack – Get compilation source
import { createFsFromVolume, Volume } from 'memfs'
const fs = createFsFromVolume(new Volume())
const compiler = webpack({
entry: 'file.js',
output: { filename: 'main.js' }
})
// Compile the file to memory.
compiler.outputFileSystem = fs
await new Promise((resolve, reject) => compiler.run((error) => {
if (error) reject(error)
resolve()
})
// Read the compiled file from memory.
const source = memoryFs.readFileSync('dist/main.js', 'utf8').toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment