zoukankan      html  css  js  c++  java
  • 配置本地服务器

    一:用node配置(确保有node)

    1. npm install http-server 

    2.cd  到指定目录

    3.http-server

    二:webpack配置

    1.在config里的index.js中

    function getIPAdress(){
    var interfaces = require('os').networkInterfaces();
    for(var devName in interfaces){
    var iface = interfaces[devName];
    for(var i=0;i<iface.length;i++){
    var alias = iface[i];
    if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
    console.log(alias.address)
    return alias.address;
    }
    }
    }
    }
     
    2.在dev中host修改为如下
    module.exports = {
    dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: getIPAdress(), // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

     三.gulp配置
    1.
    //获取当前ip
    const getIPAdress = (function(){
    var interfaces = require('os').networkInterfaces();
    for(var devName in interfaces){
    var iface = interfaces[devName];
    for(var i=0;i<iface.length;i++){
    var alias = iface[i];
    if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
    console.log(alias.address)
    return alias.address;
    }
    }
    }
    })();
    2.
    // 服务器
    gulp.task('server', function() {
    var BASEURL = command=='watchapi'?'https://api.bianla.cn/':"https://dev.bianla.cn/";
    var BASEURL2 = command=='watchapi'?'https://apibbs.bianla.cn/':"https://devbbs.bianla.cn/";
    browser.server({
    host: getIPAdress, //地址,可不写,不写的话,默认localhost
    // port: 8000, //端口号,可不写,默认8000
    root: `${pathObj.path}/test`, //当前项目主目录
    livereload: true, //自动刷新
    middleware:function(connect,opt){
    return [proxy('/APIBIANLA',{
    target:BASEURL,
    changeOrigin:true,
    pathRewrite:{"/APIBIANLA" :BASEURL}
    }),
    proxy('/APIBBSBIANLA',{
    target:BASEURL2,
    changeOrigin:true,
    pathRewrite:{"/APIBBSBIANLA" :BASEURL2}
    })]
    }
    });
    });
    3.
    gulp.task('watch',['server'],()=>{
    gulp.watch(`${pathObj.path}/dev/lib/*.js`,['js']);
    gulp.watch([`${path.resolve("../")}/assets/js/*.js`,`${path.resolve("../")}/assets/styles/*.less`],['common']);
    gulp.watch(`${pathObj.path}/dev/styles/*.less`,['less']);
    gulp.watch([`${pathObj.path}/dev/*.html`,`${pathObj.path}/dev/template/**/*.html`],['html']);
    });
     
  • 相关阅读:
    C#获取中英文混合字符串长度和截取函数
    页面和块高度在JavaScript中的属性总结
    跨浏览器兼容添加到收藏夹/书签的Javascript
    转:28个免费的在线文件格式转换工具
    2009年十大经典网络小说
    某企业网站建设步骤
    转:Web安全工具大汇聚
    枚举
    VS中不显示解决方案的解决方法
    SQL 分页存储过程
  • 原文地址:https://www.cnblogs.com/miaSlady/p/9997787.html
Copyright © 2011-2022 走看看