0

你的工作场所是什么?

你好,我想问一下你的前端和后端同时开发的方法是什么?

我喜欢 Webpack,但是,当我想编辑框架时该怎么办?

我需要开箱即用地运行 webpack 吗?

是否可以将 webpack --watch 或其他一些模块引用到服务器作为代理?如果是这样,如何在更改时设置 *.php 文件以强制刷新页面。

到目前为止,我已经在框架上单独工作,特别是在前端。现在我真的不知道如何组合在一起,尤其是当 webpack2 的许多模块已经过时时。

Windows X, Docker(laradock), Webpack, SASS, JS, PHP

感谢您对未来的建议。

4

1 回答 1

1

你应该使用 webpack-dev-server 作为代理来支持多个主机。然后,您将能够从服务器加载“后端”并使用 webpack MHR 内联的所有好处在另一个环境中进行开发。

这是我的webpack.config.js

var path = require('path');
var htmlWebPack = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack')
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');

var buildPath = path.join(__dirname);           // Local /public/
var serverURL = 'http://localhost:8080/'        // Webpack-dev-server
var proxyURL = 'http://LaraDock.dev:85/'        // External server (laradock)
var proxy = {
    '*': proxyURL
};




module.exports = {
    devtool: 'cheap-eval-source-map',
    context: path.join(__dirname, 'resources'), // ABSOLUTE ROUTE ./
    entry: {
        app:    [
            'webpack-dev-server/client?' + serverURL,
            'webpack/hot/only-dev-server',
            path.join(__dirname, 'resources/assets/js/app.js')
        ]
    },


output: {
    publicPath: serverURL + buildPath,
    path: path.resolve(__dirname, buildPath),
    filename: "js/[name].bundle.js"
},
resolve: {
    alias: {
        'vue$': 'vue/dist/vue.common.js'
    },
},

module: {
    loaders: [
    // JS
        {
            test: /\.js$/,      // ON WHAT TYPE USE THIS LOADER
            loader: 'babel-loader',
            include: path.join(__dirname, 'resources', 'assets', 'js'),
        },

    // VUE
        {
            test: /\.vue$/,
            loader: 'vue-loader',
            include: path.join(__dirname, 'resources', 'assets', 'js'),
        },

    // STYLE
        {
            test: /\.(sass|scss|css)$/,
            loader: ['style-loader', 'css-loader', 'sass-loader'],
            include: path.join(__dirname, 'resources', 'assets', 'scss'),
        },

    // FILES
        {
            test: /\.(jpe?g|png|gif|svg|ico)$/i,
            loader: "file-loader?name=[path][name].[ext]&context=./resources/assets"
        },

    // FONTS
        {
            test: /\.(otf|eot|svg|ttf|woff)$/,
            loader: 'url-loader?limit=10000'
        },

        {
            test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: "url-loader?limit=10000"
        },

        {
            test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
            loader: 'file-loader'
        },

    // BOOTSTRAP
        {
            test: /bootstrap\/public\/js\/umd\//,
            loader: 'imports?jQuery=jquery'
        },
     ],
},


devServer: {
    contentBase: serverURL + buildPath,
    proxy: proxy,
    historyApiFallback: true,
    hot: true,
    noInfo: true,
    stats: {
        errors: true,
        colors: true,
        errorDetails: true,
        reasons: false,
        hash: false,
        version: false,
        timings: false,
        assets: false,
        chunks: false,
        modules: false,
        children: false,
        source: false,
        warnings: false,
        publicPath: false
    }
},


plugins: [
    new webpack.NoEmitOnErrorsPlugin(),

    new BrowserSyncPlugin(
                // BrowserSync options
                {
                    // Webpack-dev-server endpoint
                    host: 'http://localhost',
                    port: 80,
                    // proxy the Webpack Dev Server endpoint
                    // (which should be serving on http://localhost:80/) through BrowserSync
                    proxy: serverURL,
                    // Files
                    files: ['public/*', 'app/**/*.php', 'config/**/*.php', 'resources/views/**/*.php'],
                },
                // plugin options
                {
                    // prevent BrowserSync from reloading the page
                    // and let Webpack Dev Server take care of this
                    reload: false
    }),

    new ExtractTextPlugin({
        filename: './css/[name].style.css',
        disable: false,
        allChunks: true
    }),

    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery",
        "Tether": 'tether' // Bootstrap v4 problem
    }),

    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin()
],

};

于 2017-03-14T00:58:02.307 回答