Created
April 25, 2020 11:51
-
-
Save pagameba/b3f8aa27bf2c1bcaed9a2e0cf7cf5eec to your computer and use it in GitHub Desktop.
This file contains 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
export async function test() { } |
This file contains 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
const path = require("path") | |
const fs = require('fs') | |
const defaultConfig = require("@parcel/config-default") | |
const { default: Parcel, createWorkerFarm } = require("@parcel/core") | |
const { NodeFS, MemoryFS } = require("@parcel/fs") | |
const workerFarm = createWorkerFarm() | |
const nodeFS = new NodeFS() | |
const memoryFS = new MemoryFS(workerFarm) | |
// set to memoryFS to using the memory file system as input | |
let inputFS = nodeFS | |
const BASE_PATH = '/build' | |
const SRC_PATH = `${BASE_PATH}/src` | |
const DIST_PATH = `${BASE_PATH}/dist` | |
const CODE_PATH = path.join(__dirname, 'src', 'api.js') | |
const bundler = new Parcel({ | |
entries: inputFS == memoryFS ? `${SRC_PATH}/api.js` : CODE_PATH, | |
cache: false, | |
defaultConfig: { | |
...defaultConfig, | |
filePath: require.resolve("@parcel/config-default"), | |
}, | |
defaultEngines: { | |
browsers: ["last 1 Chrome version"], | |
}, | |
targets: { | |
main: { | |
engines: { browsers: ["last 1 Chrome version"] }, | |
distDir: `${DIST_PATH}` | |
} | |
}, | |
inputFS: inputFS, | |
outputFS: memoryFS, | |
workerFarm, | |
}) | |
fs.readFile(path.join(__dirname, 'src', 'api.js'), async (err, code) => { | |
await memoryFS.mkdirp(SRC_PATH) | |
await memoryFS.mkdirp(DIST_PATH) | |
await memoryFS.writeFile(`${SRC_PATH}/api.js`, code) | |
console.log('bunder starting') | |
await bundler.run() | |
console.log('bunder complete') | |
const files = await memoryFS.readdir("/build/dist/") | |
for (let file of files) { | |
console.log(file) | |
} | |
await workerFarm.end() | |
}); |
This file contains 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
{ | |
"name": "parcel-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"parcel": "^2.0.0-alpha.3.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment