webpack.config.js 中代理配置,用作跨域访问

   devServer: {
          port:8001,
          contentBase: './',// boolean | string | array, static file location
          compress: true, // enable gzip compression
         historyApiFallback: true, // true for index.html upon 404, object for multiple paths
          hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
         https: false, // true for self-signed, object for cert authority
         noInfo: true, // only errors & warns on hot reload
          host:'192.168.0.56',
         proxy: [
             {
                  context: ['/dist/*'],
                  target: 'http://localhost',
                  changeOrigin: true,
                 secure: false
              },
          ]
      },

整个wenback配置

var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var node_dir = path.join(__dirname, './node_modules/');
var htmlPlugin = require('html-webpack-plugin');

// 判断是否是在当前生产环境
var isProduction = process.env.NODE_ENV === 'production';
if(process.env.NODE_ENV)
{
    console.log("--------"+process.env.NODE_ENV.toString());
}
console.log("--------"+isProduction);
module.exports = {
    entry: {
        app: ['./src/app.jsx']
    },
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.js',
        publicPath: isProduction?'../':'/dist/',
        chunkFilename: '[name].chunk.js'
    },
    module: {
        loaders: [{
            // test: /\.jsx?$/,
            test: /(\.jsx|\.js)$/,
            loader: 'babel',
            query: {
                presets: ['es2015', 'react','es2017']
            },
            exclude: node_dir
        }, {
            test: /\.css$/,
            loader: ExtractTextPlugin.extract('style', 'css')
        }, {
            test: /\.less$/,
            loader: ExtractTextPlugin.extract('style', 'css!less')
        },
            {
                test: /\.(png|jpe?g|gif)$/,
                loader: 'url?limit=1024000&name=img/[name].[ext]'
            },
            {
                test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                loader: 'file?limit=1&name=fonts/[name].[ext]'
            }]
    },
    resolve: {
        extensions: ['', '.js', '.jsx', '.json', '.css', '.less'],
        alias: {
            // libs: path.join(__dirname, "./web/libs"),
            style: path.join(__dirname, "./src/style"),
            img: path.join(__dirname, "./src/img"),
            view: path.join(__dirname, "./src/view"),
            utils: path.join(__dirname, "./src/util")
        }
    },
      devServer: {
          port:8001,
          contentBase: './',// boolean | string | array, static file location
          compress: true, // enable gzip compression
         historyApiFallback: true, // true for index.html upon 404, object for multiple paths
          hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
         https: false, // true for self-signed, object for cert authority
         noInfo: true, // only errors & warns on hot reload
          host:'192.168.0.56',
         proxy: [
             {
                  context: ['/dist/*'],
                  target: 'http://localhost',
                  changeOrigin: true,
                 secure: false
              },
          ]
      },
    plugins: [
        new webpack.ProvidePlugin({
            React: 'react', // 使react变成全局变量
            ReactDOM: 'react-dom'
        }),
        new webpack.NoErrorsPlugin(),
        new ExtractTextPlugin('css/[name].css'),
        // new htmlPlugin({
        //     template: './web/template.html',
        //     filename: 'index.html'
        // }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devtool: isProduction ? null : 'source-map'
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值