How to use the webpack.NormalModuleReplacementPlugin function in webpack

To help you get started, we’ve selected a few webpack 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 Automattic / wp-desktop / webpack.shared.js View on Github external
],
	resolve: {
		extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ],
		modules: [
			'node_modules',
			path.join( __dirname, 'calypso', 'node_modules' ),
			path.join( __dirname, 'node_modules' ),
			path.join( __dirname, 'calypso', 'server' ),
			path.join( __dirname, 'calypso', 'client' ),
			path.join( __dirname, 'desktop' ),
		],
	},
	plugins: [
		new webpack.NormalModuleReplacementPlugin( /^lib[\/\\]abtest$/, 'lodash/noop' ), // Depends on BOM
		new webpack.NormalModuleReplacementPlugin( /^lib[\/\\]analytics$/, 'lodash/noop' ), // Depends on BOM
		new webpack.NormalModuleReplacementPlugin( /^lib[\/\\]sites-list$/, 'lodash/noop' ), // Depends on BOM
		new webpack.NormalModuleReplacementPlugin( /^lib[\/\\]olark$/, 'lodash/noop' ), // Depends on DOM
		new webpack.NormalModuleReplacementPlugin( /^lib[\/\\]user$/, 'lodash/noop' ), // Depends on BOM
		new webpack.NormalModuleReplacementPlugin(
			/^lib[\/\\]post-normalizer[\/\\]rule-create-better-excerpt$/,
			'lodash/noop'
		), // Depends on BOM
		new webpack.NormalModuleReplacementPlugin(
			/^components[\/\\]seo[\/\\]reader-preview$/,
			'components/empty-component'
		), // Conflicts with component-closest module
		new webpack.NormalModuleReplacementPlugin(
			/^components[\/\\]popover$/,
			'components/null-component'
		), // Depends on BOM and interactions don't work without JS
		new webpack.NormalModuleReplacementPlugin(
			/^my-sites[\/\\]themes[\/\\]theme-upload$/,
github codesandbox / codesandbox-client / packages / app / config / webpack.common.js View on Github external
// Watcher doesn't work well if you mistype casing in a path so we use
    // a plugin that prints an error when you attempt to do this.
    // See https://github.com/facebookincubator/create-react-app/issues/240
    new CaseSensitivePathsPlugin(),

    // With this plugin we override the load-rules of eslint, this function prevents
    // us from using eslint in the browser, therefore we need to stop it!
    !SANDBOX_ONLY &&
      new webpack.NormalModuleReplacementPlugin(
        new RegExp(['eslint', 'lib', 'load-rules'].join(sepRe)),
        path.join(paths.config, 'stubs/load-rules.compiled.js')
      ),

    // DON'T TOUCH THIS. There's a bug in Webpack 4 that causes bundle splitting
    // to break when using lru-cache. So we literally gice them our own version
    new webpack.NormalModuleReplacementPlugin(
      /^lru-cache$/,
      path.join(paths.config, 'stubs/lru-cache.js')
    ),

    // If you require a missing module and then `npm install` it, you still have
    // to restart the development server for Webpack to discover it. This plugin
    // makes the discovery automatic so you don't have to restart.
    // See https://github.com/facebookincubator/create-react-app/issues/186
    new WatchMissingNodeModulesPlugin(paths.appNodeModules),
  ].filter(Boolean),
};
github mozilla / addons-frontend / webpack.dev.config.babel.js View on Github external
publicPath: `//${webpackHost}:${webpackPort}/`,
  },
  module: {
    rules: getRules({ babelOptions, bundleStylesWithJs: true }),
  },
  plugins: [
    ...getPlugins(),
    // Load unminified React and Redux in development to get better error
    // messages, because they use
    // [Invariant](https://github.com/zertosh/invariant) which hides error
    // messages in the production build.
    new webpack.NormalModuleReplacementPlugin(
      /^react$/,
      'react/umd/react.development.js',
    ),
    new webpack.NormalModuleReplacementPlugin(
      /^react-dom$/,
      'react-dom/umd/react-dom.development.js',
    ),
    new webpack.NormalModuleReplacementPlugin(/^redux$/, 'redux/dist/redux.js'),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.IgnorePlugin(/webpack-stats\.json$/),
    webpackIsomorphicToolsPlugin.development(),
  ],
};
github mlaursen / react-md / documentation / webpack.config.js View on Github external
use: [{
          loader: 'url-loader',
          options: {
            limit: 10240,
          },
        }, {
          loader: 'image-webpack-loader',
          options: {
            bypassOnDebug: true,
          },
        }],
      }],
    },
    plugins: [
      // Use async routes in production and synchronous in development
      new webpack.NormalModuleReplacementPlugin(
        /routes$/,
        `routes/${production ? 'a' : ''}sync.js`
      ),
      new webpack.NormalModuleReplacementPlugin(
        /^\.\/routes$/,
        `./${production ? 'a' : ''}sync.js`
      ),
      new webpack.LoaderOptionsPlugin({
        options: {
          eslint: {
            failOnError: true,
          },
          context: '/',
          debug: !production,
        },
      }),
github Sitecore / jss / samples / basic-sample-angular / webpack.server.config.js View on Github external
__dirname: false,
    __filename: false,
  },
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/(node_modules|main\..*\.js)/],
  output: {
    filename: '[name].bundle.js',
    libraryTarget: 'commonjs' // ensures server.ts renderView is exposed as a public method.
  },
  module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader' }
    ]
  },
  plugins: [
    new webpack.NormalModuleReplacementPlugin(/\.\.\/environments\/environment/, '../environments/environment.server'),
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for "WARNING Critical dependency: the request of a dependency is an expression"
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    )
  ]
}
github josdejong / jsoneditor / config / webpack.config.minimalist.js View on Github external
const webpack = require('webpack')
const config = require('./webpack.config')
const emptyFile = __dirname + '/../src/jsoneditor/utils/empty.js'

const excludeAcePlugin = new webpack.NormalModuleReplacementPlugin(new RegExp('assets\/ace'), emptyFile)
const excludeAjvPlugin = new webpack.NormalModuleReplacementPlugin(new RegExp('^ajv$'), emptyFile)

const configMinimalist = Object.assign({}, config, {
  output: Object.assign({}, config.output, {
    filename: 'dist/jsoneditor-minimalist.js'
  }),

  plugins: [
    excludeAcePlugin,
    excludeAjvPlugin
  ].concat(config.plugins)
})

module.exports = configMinimalist
github Maarten88 / rrod / src / Webapp / webpack.config.js View on Github external
instance: 'at-server'
                            }
                        }
                    ]
                },
                {
                    test: /\.svg$/,
                    use: {
                        loader: 'url-loader',
                        options: { limit: 25000 } //?limit=100000'
                    }
                }
            ]
        },
        plugins: [
            new webpack.NormalModuleReplacementPlugin(
                /\/iconv-loader$/, 'node-noop',
              )
        ],
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node'
    });

    return [clientBundleConfig, serverBundleConfig];
};
github expo / expo / apps / native-component-list / webpack / webpack.common.js View on Github external
function useWebModule(modulePathToHiJack, redirectPath, initialRoot = 'expo/build/web/') {
    return new webpack.NormalModuleReplacementPlugin(
      new RegExp(modulePathToHiJack),
      getWebModule(initialRoot, redirectPath)
    );
  }
github martinandert / react-inline / example / webpack.config.js View on Github external
function plugins() {
  var all = [
    new webpack.NormalModuleReplacementPlugin(/^react$/, 'react/addons')
  ];

  var production = [
    new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
    new webpack.optimize.DedupePlugin(),
    new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production') } })
  ];

  return PRODUCTION ? all.concat(production) : all;
}
github vsternbach / angularjs-typescript-webpack / webpack.config.js View on Github external
new HtmlWebPackPlugin({
      template: sourcePath + '/index.html'
    }),
    new MiniCssExtractPlugin({
      filename: '[name].[contenthash:4].css',
      chunkFilename: '[id].[contenthash:4].css'
    }),
    new ForkTsCheckerWebpackPlugin({
      tslint: true,
      checkSyntacticErrors: true
    })
  ];

  if (isProd) {
    plugins.push(
      new webpack.NormalModuleReplacementPlugin(
        /\/environments\/environment\.ts/,  `${sourcePath}/environments/environment.prod.ts`
      ),
      new UglifyJsPlugin({ sourceMap: true })
    );
  } else {
    plugins.push(new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin());
  }

  const config = {
    entry: {
      app: sourcePath + '/main.ts',
    },
    output: {
      path: distPath,
      filename: '[name].bundle.[hash:4].js',
    },