How to use the enhanced-resolve.NodeJsInputFileSystem function in enhanced-resolve

To help you get started, we’ve selected a few enhanced-resolve 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 realywithoutname / mini-program-webpack-loader / lib / MiniPlugin.js View on Github external
apply(compiler) {
    this.compiler = compiler;
    this.outputPath = compiler.options.output.path;
    this.compilerContext = join(compiler.context, 'src');

    this._appending = [];

    // 向 loader 中传递插件实例
    loader.$applyPluginInstance(this);

    // 使用模板插件,用于设置输出格式
    new MiniTemplate(this).apply(compiler);
    new ProgressPlugin({ handler: this.progress }).apply(compiler);

    const resolver = ResolverFactory.createResolver(Object.assign({
      fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
      extensions: ['.js', '.json']
    }, this.compiler.options.resolve));

    this.resolver = (context, request) => {
      return new Promise((resolve, reject) => {
        resolver.resolve({}, context, request, {}, (err, res) => err ? reject(err) : resolve(res));
      });
    };

    this.miniEntrys = utils.formatEntry(compiler.options.entry, this.chunkNames);

    // 获取打包后路径(在 loader 中有使用)
    this.getDistFilePath = () => {};

    // hooks
    this.compiler.hooks.environment.tap('MiniPlugin', this.setEnvHook.bind(this));
github sverweij / dependency-cruiser / src / main / resolveOptions / normalize.js View on Github external
// node_modules/@types we need:
  // - the inclusion of .d.ts to the extensions (see above)
  // - an explicit inclusion of node_modules/@types to the spots
  //   to look for modules (in addition to "node_modules" which
  //   is the default for enhanced-resolve)
  modules: ["node_modules", "node_modules/@types"]
};

const NON_OVERRIDABLE_RESOLVE_OPTIONS = {
  // This should cover most of the bases of dependency-cruiser's
  // uses. Not overridable for now because for other
  // file systems it's not sure we can use sync system calls
  // Also: passing a non-cached filesystem makes performance
  // worse.
  fileSystem: new enhancedResolve.CachedInputFileSystem(
    new enhancedResolve.NodeJsInputFileSystem(),
    CACHE_DURATION
  ),
  // our code depends on sync behavior, so having this
  // overriden is not an option
  useSyncFileSystemCalls: true
};

function pushPlugin(pPlugins, pPluginToPush) {
  return (pPlugins || []).concat(pPluginToPush);
}

function compileResolveOptions(pResolveOptions, pTSConfig) {
  let lResolveOptions = {};

  // TsConfigPathsPlugin requires a baseUrl to be present in the
  // tsconfig, otherwise it prints scary messages that it didn't
github antonmedv / jsize / index.js View on Github external
'use strict'

const path = require('path')
const os = require('os')
const execFile = require('execa')
const webpack = require('webpack')
const minify = require('babel-minify')
const gzipSize = require('gzip-size')
const MemoryFs = require('memory-fs')
const Buffer = require('buffer').Buffer
const parsePackageName = require('parse-package-name')
const enhancedResolve = require('enhanced-resolve')
const tmp = path.join(os.tmpdir(), 'jsize-' + Math.random().toString(36).substring(7))
const npmBin = path.join(require.resolve('npm/package.json'), '../../.bin/npm')
const resolver = enhancedResolve.ResolverFactory.createResolver({
  fileSystem: new enhancedResolve.NodeJsInputFileSystem(),
  mainFields: ['browser', 'module', 'main']
})
require('fs').mkdirSync(tmp)

/**
 * Calculates the sizes (initial, minified and gziped) for a given package.
 *
 * @param {string|string[]} pkgs - the package(s) to check the size of.
 * @return {Promise}
 */
module.exports = function jsize (pkgs) {
  // Parse all package details. (allows for single or multiple packages)
  pkgs = [].concat(pkgs).map(parsePackageName)
  // Get unique package ids.
  const ids = pkgs
    .map(it => it.name + '@' + (it.version || 'latest'))
github ryanelian / instapack / src / ConcatBuildTool.ts View on Github external
import * as fse from 'fs-extra';
import * as upath from 'upath';
import chalk from 'chalk';
import { NodeJsInputFileSystem, ResolverFactory } from 'enhanced-resolve';
import * as UglifyJS from 'uglify-js';

import { Settings } from './Settings';
import { outputFileThenLog } from './CompilerUtilities';
import { Shout } from './Shout';
import { prettyHrTime } from './PrettyUnits';

let resolver = ResolverFactory.createResolver({
    fileSystem: new NodeJsInputFileSystem(),
    extensions: ['.js'],
    mainFields: ['unpkg', 'browser', 'main']
});

/**
 * Contains methods for concatenating JS files.
 */
export class ConcatBuildTool {

    /**
     * Gets the project settings.
     */
    private readonly settings: Settings;

    /**
     * Gets the compiler build flags.
github stryker-mutator / stryker / packages / stryker-webpack-transpiler / src / fs / InputFileSystem.ts View on Github external
  constructor(innerFS = new NodeJsInputFileSystem()) {
    super(innerFS, CACHE_DURATION);
  }
github realywithoutname / mini-program-webpack-loader / src / helpers / create-resolver.js View on Github external
module.exports.createResolver = function (compiler) {
  const resolver = ResolverFactory.createResolver(
    Object.assign(
      {
        fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
        extensions: ['.js', '.json']
      },
      compiler.options.resolve
    )
  )

  return (context, request) => {
    return new Promise((resolve, reject) => {
      resolver.resolve({}, context, request, {}, (err, res) => err ? reject(err) : resolve(res))
    })
  }
}