How to use the import-from.silent function in import-from

To help you get started, we’ve selected a few import-from 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 react-cosmos / react-cosmos / packages / react-cosmos / src / server / web / export.js View on Github external
export async function generateExport() {
  const cosmosConfig = getCosmosConfig();
  const { rootPath, outputPath, publicPath, publicUrl } = cosmosConfig;

  const webpack = silentImport(rootPath, 'webpack');
  if (!webpack) {
    console.warn('[Cosmos] webpack dependency missing!');
    console.log('Install using "yarn add webpack" or "npm install webpack"');
    return;
  }

  const userWebpackConfig = getUserWebpackConfig(cosmosConfig);
  const loaderWebpackConfig = enhanceWebpackConfig({
    webpack,
    userWebpackConfig,
    shouldExport: true
  });

  // Copy static files first, so that the built index.html overrides the its
  // template file (in case the static assets are served from the root path)
  if (publicPath) {
github react-cosmos / react-cosmos / packages / react-cosmos / src / server / web / webpack / enhance-webpack-config.js View on Github external
NODE_ENV: JSON.stringify(shouldExport ? 'production' : 'development'),
        PUBLIC_URL: JSON.stringify(removeTrailingSlash(publicUrl))
      }
    }),
    new webpack.DefinePlugin({
      COSMOS_CONFIG: JSON.stringify({
        // Config options that are available inside the client bundle. Warning:
        // Must be serializable!
        containerQuerySelector
      })
    }),
    getNoErrorsPlugin(webpack)
  ];

  if (!alreadyHasPlugin(webpackConfig, 'HtmlWebpackPlugin')) {
    const HtmlWebpackPlugin = silentImport(rootPath, 'html-webpack-plugin');

    if (HtmlWebpackPlugin) {
      plugins = [
        ...plugins,
        new HtmlWebpackPlugin({
          title: 'React Cosmos',
          filename: '_loader.html'
        })
      ];
    }
  }

  if (hot && !shouldExport) {
    if (!alreadyHasPlugin(webpackConfig, 'HotModuleReplacementPlugin')) {
      plugins = [...plugins, new webpack.HotModuleReplacementPlugin()];
    }
github react-cosmos / react-cosmos / packages / react-cosmos / src / server / web / webpack / default-webpack-config.js View on Github external
// React.componentDidCatch https://github.com/facebook/react/issues/10441
    devtool: 'cheap-module-source-map',
    resolve: {
      // Warning: webpack 1.x expects ['', '.js', '.jsx']
      extensions: ['.js', '.jsx']
    },
    module: {
      // Note: `module.rules` only works with webpack >=2.x. For 1.x
      // compatibility a custom webpack config (with module.loaders) is required
      rules
    },
    plugins
  };

  // Add mode option for webpack 4+
  const webpack = silentImport(rootPath, 'webpack');

  if (webpack.version && parseInt(webpack.version, 10) >= 4) {
    // Disallow non dev/prod environments, like "test" inside Jest, because
    // they are not supported by webpack
    const mode =
      process.env.NODE_ENV === 'production' ? 'production' : 'development';

    config = {
      ...config,
      mode,
      optimization: {
        // Cosmos reads component names at run-time, so it is crucial to not
        // minify even when building with production env (ie. when exporting)
        // https://github.com/react-cosmos/react-cosmos/issues/701
        minimize: false
      }
github react-cosmos / react-cosmos / packages / react-cosmos / src / plugins / webpack / shared.ts View on Github external
export function getWebpack(rootDir: string) {
  const userWebpack = importFrom.silent(rootDir, 'webpack');
  if (!userWebpack) {
    console.warn('[Cosmos] webpack dependency missing!');
    console.log(
      'Install using "yarn add --dev webpack" or "npm install --save-dev webpack"'
    );
    return;
  }

  return userWebpack;
}
github react-cosmos / react-cosmos / packages / react-cosmos / src / server / web / start.js View on Github external
console.log(`[Cosmos] Nice! You're using ${generatedConfigFor}`);
      console.log('[Cosmos] Generated a tailored config file for your setup');
    }
  }

  const cosmosConfig = getCosmosConfig();
  const { next, rootPath, publicUrl } = cosmosConfig;

  if (cosmosConfig.proxies) {
    console.warn('[Cosmos] Warning: config.proxies is deprecated!');
    console.warn(
      'Please check latest proxy docs: https://github.com/react-cosmos/react-cosmos#proxies'
    );
  }

  const webpack = silentImport(rootPath, 'webpack');
  if (!webpack) {
    console.warn('[Cosmos] webpack dependency missing!');
    console.log('Install using "yarn add webpack" or "npm install webpack"');

    return () => {};
  }

  const userWebpackConfig = getUserWebpackConfig(cosmosConfig);
  const app = createServerApp({
    cosmosConfig,
    playgroundOpts: getPlaygroundOpts(cosmosConfig)
  });
  const { server, startServer, stopServer } = createServer(cosmosConfig, app);

  const publicPath = getPublicPath(cosmosConfig, userWebpackConfig);
  if (publicPath) {
github wix / haste / packages / haste-cli / src / utils.js View on Github external
module.exports.loadConfig = (appDirectory) => {
  const packageJson = importFrom.silent(appDirectory, './package.json');

  if (!packageJson) {
    return null;
  }

  const { haste } = packageJson;

  if (!haste) {
    return null;
  }

  return haste;
};
github react-cosmos / react-cosmos / packages / react-cosmos / src / plugins / webpack / webpackConfig / htmlPlugin.ts View on Github external
export function getHtmlWebpackPlugin(rootDir: string) {
  return importFrom.silent(
    rootDir,
    'html-webpack-plugin'
  );
}
github marp-team / marp-cli / src / engine.ts View on Github external
;(Array.isArray(engine) ? engine : [engine]).some(eng => {
      if (typeof eng === 'string') {
        resolved =
          (from && importFrom.silent(path.dirname(path.resolve(from)), eng)) ||
          importFrom.silent(process.cwd(), eng)

        if (resolved?.__esModule) resolved = resolved.default
      } else {
        resolved = eng
      }
      return resolved
    })
github sindresorhus / atom-esformatter / index.js View on Github external
allowUnsafeNewFunction(() => {
		esformatter = importFrom.silent(path.dirname(fp), 'esformatter') || require('esformatter');
	});
github semantic-release / commit-analyzer / lib / load-release-rules.js View on Github external
module.exports = ({releaseRules}, {cwd}) => {
  let loadedReleaseRules;

  if (releaseRules) {
    loadedReleaseRules =
      typeof releaseRules === 'string'
        ? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
        : releaseRules;

    if (!Array.isArray(loadedReleaseRules)) {
      throw new TypeError('Error in commit-analyzer configuration: "releaseRules" must be an array of rules');
    }

    loadedReleaseRules.forEach(rule => {
      if (!rule || isUndefined(rule.release)) {
        throw new Error('Error in commit-analyzer configuration: rules must be an object with a "release" property');
      } else if (!RELEASE_TYPES.includes(rule.release) && rule.release !== null && rule.release !== false) {
        throw new Error(
          `Error in commit-analyzer configuration: "${
            rule.release
          }" is not a valid release type. Valid values are: ${JSON.stringify(RELEASE_TYPES)}`
        );
      }

import-from

Import a module like with `require()` but from a given path

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular import-from functions