How to use the parcel-bundler/src/utils/fs.mkdirp function in parcel-bundler

To help you get started, we’ve selected a few parcel-bundler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kevincharm / parcel-plugin-web-extension / src / WebExtensionPackager.js View on Github external
async resolveAssetContents(asset) {
        let contents = asset.generated[this.bundle.type]
        if (!contents || (contents && contents.path)) {
            contents = await fs.readFile(contents ? contents.path : asset.name)
        }

        console.log(asset.generated)

        // Create sub-directories if needed
        if (this.bundle.name.includes(path.sep)) {
            await fs.mkdirp(path.dirname(this.bundle.name))
        }

        // Add the hot-reload.js script to background scripts
        const json = JSON.parse(contents)
        json.background = json.background || {}
        json.background.scripts = json.background.scripts || []
        json.background.scripts.unshift('hot-reload.js')
        contents = JSON.stringify(json)

        return contents
    }
github kevincharm / parcel-plugin-web-extension / src / WebExtensionPackager.js View on Github external
async addAsset(asset) {
        const artifactsDir = path.resolve(
            asset.options.outDir,
            '..',
            'artifacts'
        )
        await fs.mkdirp(artifactsDir)

        // Write the manifest.json
        const bundlePath = path.parse(this.bundle.name)
        const contents = await this.resolveAssetContents(asset)
        const hotReloadScriptFilename = path.resolve(
            bundlePath.dir,
            'hot-reload.js'
        )
        await fs.writeFile(hotReloadScriptFilename, hotReloadScript, {
            encoding: 'utf8'
        })
        const manifestJsonFilename = path.resolve(
            bundlePath.dir,
            bundlePath.name + '.json'
        )
        await fs.writeFile(manifestJsonFilename, contents, { encoding: 'utf8' })