Webpack doesn't find php file

Viewed 148

I have a formula with an action call but the PHP script is not found after the click action. I use webpack and all PHP loaders are charging in my package.json . On my screen, I get the following error response:

Cannot POST /mail.php along with a 404 error code.

My webpack.config.js :

module: {
    rules: [
        {
            test: /\.html$/,
            use: 'html-loader'
        },
        {
            test: /\.php$/,
            use: 'php-loader'
        },
        {
            test: /\.scss$/,
            use: ['style-loader','css-loader','postcss-loader', 'sass-loader'],
        },
        {
            test: /\.(png|jpg|gif)$/,
            use:
                {
                    loader : 'file-loader',
                    options : {
                        context: path.join(__dirname, '/src'),
                        name: '[path][name].[ext]',
                        esModule: false,
                    }
                }
        },
        {
            test: /\.(woff(2)?|ttf|eot|svg)$/,
            use:
                {
                    loader : 'file-loader',
                    options : {
                        name: '[path][name].[ext]',
                    }
                }
        },
        {
            enforce: 'pre',
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'eslint-loader',
        },
        {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
            }
        },
    ]
},
1 Answers

This is rather an old question but I had exactly the same problem so thought I'd answer in case anyone else had the same issue. You can import a PHP file (CSS as well) into a javascript file. This also doesn't break the file if you just run it directly (with no webpacking).

import './style.css';
import './index.php';

Webpack then goes and gets these files and loads them in according to the loaders. I presume the reasoning here is that loaders themselves don't do the discovering of files just handle the files that are discovered.

Related