Last active
February 9, 2021 17:23
-
-
Save kettanaito/c1b7cf1242a03c2e934a21c1e736cc9a to your computer and use it in GitHub Desktop.
Webpack – Get compilation source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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