Search code examples
webpack-2

Ignore the require statement on webpack 2 bundling time and exclude that require statement from the bundled js


I implement a React.Component in a.js. This file will be used for client and server side rendering. Of course a.js has require("a.scss")

Is there a way to do on webpack.config.js only to tell webpack not to read all the scss` require statement during the bundling?

I did try the IgnorePlugin to *.scss. The bundling process is fine but node gives runtime error which is Cannot find module './a.scss'

Here are the unwanted suggestions

  • I don't want to use DefinePlugin or EnvironmentPlugin because I don't want to wrap the require("a.scss") inside an if statement
  • I don't want to use ExtractTextWebpackPlugin to extract the scss which is I am currently using. Let node can run the bundled js perfectly.

Solution

  • This is the solution

    {
      "test": /\.s?css$/,
      "use": "null-loader"
    }