如何将webpack dev服务器代理到vagrant vvv(wordpress)站点

时间:2017-09-04 20:16:52

标签: javascript webpack vagrant webpack-dev-server webpack-hmr

我试图为我的WordPress工作流程设置一个基本的开发环境。我想基本上使用Webpack的HMR功能来重新加载站点的部分而不重新加载。目前,它使用Syncloader来观看php,css更改和重新加载,但我更进一步使用webpack-dev-server,因此它不必每次都重新加载,但localhost只指向该文件夹。

这是我的webpack配置。

dev的:

const merge             = require( 'webpack-merge' );
const commonConfig      = require( './webpack.common.js' );
const webpack           = require( 'webpack' );

module.exports = merge( commonConfig, {
    devtool: 'eval',
    devServer: {
        compress: true,
        hot: true, 
        proxy: {
            "/api": {
                target: "mysite.dev",
                pathRewrite: {"^/api" : ""}
            }
        }    
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
               use: [
                    'style-loader',
                    'css-loader',
                    {
                        loader: 'postcss-loader', 
                        options: {
                            config: {
                                path: './config/postcss.config.js'
                            }
                        }
                    },
                    'sass-loader'
                ]
            }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify( 'development' )
            }
        })
    ]
});

常见:

const path              = require( 'path' );

module.exports = {
    entry: path.resolve( __dirname, '../assets/scripts/bundle.js' ),
    output: {
        filename: "[name].js",
        path: path.resolve( __dirname, '../dist' ),
        publicPath: ''
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: [ 'es2015' ]
                }
            },
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader' ]
            },
            {
                test: /\.(ttf|eot|woff|woff2|svg)$/,
                loader: 'file-loader',
                options: {
                    name: 'fonts/[name].[ext]'
                }
            }
        ]
    },
    plugins: [
    ]
};

0 个答案:

没有答案