How to use the @parcel/utils.urlJoin function in @parcel/utils

To help you get started, we’ve selected a few @parcel/utils 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 parcel-bundler / parcel / packages / runtimes / js / src / JSRuntime.js View on Github external
// Use esmodule loader if possible
          if (b.type === 'js' && b.env.outputFormat === 'esmodule') {
            if (!needsDynamicImportPolyfill) {
              return `import('' + '${relativeBundlePath(bundle, b)}')`;
            }

            loader = IMPORT_POLYFILL;
          } else if (b.type === 'js' && b.env.outputFormat === 'commonjs') {
            return `Promise.resolve(require('' + '${relativeBundlePath(
              bundle,
              b
            )}'))`;
          }

          let url = urlJoin(nullthrows(b.target.publicUrl), nullthrows(b.name));

          return `require(${JSON.stringify(loader)})('${url}')`;
        })
        .filter(Boolean);
github parcel-bundler / parcel / packages / core / cache / src / HTTPCache.js View on Github external
_getCachePath(cacheId: string, extension: string = '.v8'): FilePath {
    return urlJoin(this.uri, cacheId.slice(0, 2), cacheId.slice(2) + extension);
  }
github parcel-bundler / parcel / packages / runtimes / js / src / JSRuntime.js View on Github external
} else {
        for (let bundle of externalBundles) {
          let filePath = nullthrows(bundle.getMainEntry()).filePath;
          if (bundle.target == null) {
            throw new Error('JSRuntime: Bundle did not have a target');
          }

          if (bundle.target.publicUrl == null) {
            throw new Error(
              'JSRuntime: Bundle target did not have a publicUrl'
            );
          }

          assets.push({
            filePath: filePath + '.js',
            code: `module.exports = '${urlJoin(
              bundle.target.publicUrl,
              nullthrows(bundle.name)
            )}'`,
            dependency
          });
        }
      }
    }

    return assets;
  }
});
github parcel-bundler / parcel / packages / runtimes / service-worker / src / ServiceWorkerRuntime.js View on Github external
apply({bundle, bundleGraph, options}) {
    if (bundle.env.context !== 'service-worker') {
      return;
    }

    let code = `
      import {createServiceWorker} from './service-worker';
      createServiceWorker("${urlJoin(
        bundle.target.publicUrl ?? '/',
        'parcel-manifest.json'
      )}");
    `;

    return [
      {
        filePath: __filename,
        code,
        isEntry: true
      }
    ];
  }
});
github parcel-bundler / parcel / packages / packagers / html / src / HTMLPackager.js View on Github external
if (bundle.type === 'css') {
      bundles.push({
        tag: 'link',
        attrs: {
          rel: 'stylesheet',
          href: urlJoin(
            nullthrows(bundle.target).publicUrl ?? '/',
            nullthrows(bundle.name),
          ),
        },
      });
    } else if (bundle.type === 'js') {
      bundles.push({
        tag: 'script',
        attrs: {
          src: urlJoin(
            nullthrows(bundle.target).publicUrl ?? '/',
            nullthrows(bundle.name),
          ),
        },
      });
    }
  }

  addBundlesToTree(bundles, tree);
}