How to use the react-scripts/config/paths.appPath function in react-scripts

To help you get started, we’ve selected a few react-scripts 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 fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
}),
        ],
      },
    },
  ];

  oneOf.unshift(
    {
      test: /\.(woff2|woff|ttf|eot|svg)$/,
      loader: require.resolve('url-loader'),
      options: {
        limit: 10000,
        name: `${staticDir}/media/[name].[hash:8].[ext]`,
        // TODO why is this path needed?
        includePaths: [
          path.resolve(paths.appPath, 'node_modules/patternfly/dist/fonts/'),
          path.resolve(__dirname, '../../../node_modules/patternfly/dist/fonts/'),
        ],
      },
    },
    // add loaders for angular support
    {
      test: /\.html$/,
      use: ['html-loader'],
    },
    {
      test: /\.component\.css$/,
      use: ['to-string-loader', ...reactScriptsCssLoaders],
    },
    {
      test: /\.component\.less$/,
      use: [
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
},
      ],
      exclude: [/\.(spec|e2e|test)\.tsx$/],
    },
  );

  oneOf[oneOf.length - 1].exclude.push(/\.(ts|tsx)$/);

  config.plugins.push(
    new ForkTsCheckerWebpackPlugin({
      // Must set to `true` if using ts-loader `happyPackMode === true`
      checkSyntacticErrors: true,
      // We want to block webpack's emit and wait for the checker to complete and add any errors
      // to webpack's compilation.
      async: false,
      tsconfig: locateTsConfig(paths.appPath),
    }),
  );
  config.plugins.push(new IgnoreNotFoundExportPlugin());
  config.plugins.push(new ProgressBarPlugin());

  config.resolve.extensions = [
    '.mjs',
    '.web.js',
    '.js',
    '.json',
    '.web.jsx',
    '.jsx',
    '.ts',
    '.tsx',
  ];
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
},
      collectCoverageFrom: [
        'src/**/*.{js,jsx,ts,tsx}',
        '!src/**/*.d.ts',
        'packages/**/src/**/*.{js,jsx,ts,tsx}',
        '!packages/**/src/**/*.d.ts',
      ],
      testMatch: [
        '/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
        '/src/**/*.(spec|test).{js,jsx,ts,tsx}',
        '/packages/**/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
        '/packages/**/src/**/*.(spec|test).{js,jsx,ts,tsx}',
      ],
      globals: {
        'ts-jest': {
          tsConfig: locateTsConfig(paths.appPath),
        },
      },
      moduleFileExtensions: [
        'ts',
        'tsx',
        'web.js',
        'js',
        'json',
        'web.jsx',
        'jsx',
        'node',
        'mjs',
        'html',
      ],

      // TODO remove these once we can declare them in fabric8-ui
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
test: /\.component\.css$/,
      use: ['to-string-loader', ...reactScriptsCssLoaders],
    },
    {
      test: /\.component\.less$/,
      use: [
        'to-string-loader',
        ...reactScriptsCssLoaders,
        {
          loader: 'less-loader',
          options: {
            // FIXME why doesn't patternfly use ~ for referencing packages in node_modules?
            // This is such a hack....
            paths: [
              path.resolve(paths.appPath, 'node_modules'),
              path.resolve(paths.appPath, 'node_modules/patternfly/dist/less'),
              path.resolve(paths.appPath, 'node_modules/patternfly/dist/less/dependencies'),
              path.resolve(
                paths.appPath,
                'node_modules/patternfly/dist/less/dependencies/bootstrap',
              ),
              path.resolve(
                paths.appPath,
                'node_modules/patternfly/dist/less/dependencies/font-awesome',
              ),
              path.resolve(__dirname, '../../../node_modules'),
              path.resolve(__dirname, '../../../node_modules/patternfly/dist/less'),
              path.resolve(__dirname, '../../../node_modules/patternfly/dist/less/dependencies'),
              path.resolve(
                __dirname,
                '../../../node_modules/patternfly/dist/less/dependencies/bootstrap',
              ),
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
config.resolve.extensions = [
    '.mjs',
    '.web.js',
    '.js',
    '.json',
    '.web.jsx',
    '.jsx',
    '.ts',
    '.tsx',
  ];

  // Disable to prevent ts-loader with transpileOnly=true to not cause warnings about
  // exported interfaces not found
  config.module.strictExportPresence = false;

  const customWebpackPath = path.resolve(paths.appPath, 'webpack.config.js');
  if (fs.existsSync(customWebpackPath)) {
    const customConfig = require(customWebpackPath);
    config = webpackMerge(
      config,
      typeof customConfig === 'function' ? customConfig() : customConfig,
    );
  }
  require.cache[require.resolve(webpackConfig)].exports = config;
}
github fabric8-ui / fabric8-ui / talamer / packages / scripts / lib / rewire-scripts.js View on Github external
},
      collectCoverageFrom: [
        'src/**/*.{js,jsx,ts,tsx}',
        '!src/**/*.d.ts',
        'packages/**/src/**/*.{js,jsx,ts,tsx}',
        '!packages/**/src/**/*.d.ts',
      ],
      testMatch: [
        '/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
        '/src/**/*.(spec|test).{js,jsx,ts,tsx}',
        '/packages/**/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
        '/packages/**/src/**/*.(spec|test).{js,jsx,ts,tsx}',
      ],
      globals: {
        'ts-jest': {
          tsConfig: locateTsConfig(paths.appPath),
        },
      },
      moduleFileExtensions: [
        'ts',
        'tsx',
        'web.js',
        'js',
        'json',
        'web.jsx',
        'jsx',
        'node',
        'mjs',
        'html',
      ],

      // TODO remove these once we can declare them in fabric8-ui
github fabric8-ui / fabric8-ui / talamer / packages / scripts / lib / rewire-scripts.js View on Github external
require.cache[require.resolve('react-scripts/config/env')].exports = (publicUrl) => {
    const env = getClientEnvironment(publicUrl);
    const paths = require('react-scripts/config/paths');

    // Look for a `env.js` script in the app.
    // If present, load all environment variables which will be passed to the webpack DefinePlugin.
    const envScriptPath = path.resolve(paths.appPath, 'env.js');
    if (fs.existsSync(envScriptPath)) {
      const customEnv = require(envScriptPath)();
      Object.keys(customEnv).forEach((key) => {
        env.raw[key] = customEnv[key];
        env.stringified['process.env'][key] = JSON.stringify(customEnv[key]);
      });
    }

    // TODO migrate usage of ENV to NODE_ENV
    env.stringified.ENV = JSON.stringify(process.env.NODE_ENV);

    return env;
  };
}
github ghondar / crassa / react-scripts-wrapper-paths.js View on Github external
function ensureSlash(inputPath, needsSlash) {
  const hasSlash = inputPath.endsWith('/')
  if(hasSlash && !needsSlash) return inputPath.substr(0, inputPath.length - 1)
  else if(!hasSlash && needsSlash) return `${inputPath}/`
  else return inputPath
}

function getServedPath(publicUrl) {
  const servedUrl = publicUrl ? url.parse(publicUrl).pathname : '/'

  return ensureSlash(servedUrl, true)
}

paths.dotenv = existsSync(appDotEnv) ? appDotEnv : paths.dotenv
paths.appPath = appRootPath + '/'
paths.appPublic = appPublic
paths.appHtml = appPublic + '/index.html'
paths.appBuild = appBuild
paths.appPackageJson = appPackage
paths.yarnLockFile = appRootPath + '/yarn.lock'
paths.appSrc = appSrc
paths.appIndexJs = appSrc + '/index.js'
paths.proxySetup = appSrc + '/setupProxy.js'
paths.testsSetup = appSrc + '/setupTests'
paths.appNodeModules = appNodeModules
paths.servedPath = homepage ? getServedPath(homepage) : '/'
paths.publicUrl = homepage || ''

module.exports = paths
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
function rewirePaths() {
  require('react-scripts/config/env');

  const paths = require('react-scripts/config/paths');

  if (!fs.existsSync(paths.appIndexJs)) {
    paths.appIndexJs = path.resolve(paths.appPath, 'src/index.ts');
  }
  if (!fs.existsSync(paths.appPublic)) {
    paths.appPublic = path.resolve(__dirname, '../config/webpack/public');
    paths.appHtml = path.resolve(paths.appPublic, 'index.html');
  }

  require.cache[require.resolve('react-scripts/config/paths')].exports = paths;
}