Search code examples
webpackwebpack-2webpack-style-loaderhtml-webpack-plugin

how tell to webpack to use plugin or loader only for specific file?


I want to force the webpack to enable specific plugin or loader for certain file/folder, multiply files. Is there a way?


Solution

  • You can use "include" to only include a specific folder for this rule. For example (this code only compile .ts files in /app/src folder)

            {
                test: /\.ts$/,
                use: [
                    { loader: 'react-hot-loader/webpack' },
                    { loader: 'awesome-typescript-loader' }
                ],
                include: resolve(__dirname, './../app/src')
            },
    

    More examples here: https://webpack.js.org/configuration/module/#condition