Browsersync + webpack

时间:2017-04-14 09:49:22

标签: angular webpack browser-sync

我想在我的手机/平板电脑上测试我的应用,但我无法通过任何方式访问它。我正在使用webpack-dev-server服务我的应用程序,但希望通过browserync与其他设备访问它。问题是什么?页面只是加载,毕竟我得到“ERR_CONNECTION_TIMED_OUT”。它是angular2应用程序(如果它可以帮助你)。

webpack.config.js

const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');

module.exports = {
    entry: path.join(__dirname, './src/app.module.ts'),
    output: {
        path: path.join(__dirname, './dist/'),
        filename: 'bundle.js'
    },
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env'],
                        plugins: ['transform-runtime']
                    }
                }
            },
            {
                test: /\.ts$/,
                include: path.resolve(__dirname, 'src'),
                loader: 'ts-loader'
            },
            {
                test: /\.scss$/,
                include: path.resolve(__dirname, 'src'),
                use: [
                    { loader: 'style-loader' },
                    { loader: 'css-loader' },
                    { 
                        loader: 'postcss-loader',
                        options: {
                            plugins: function () {
                                return [
                                    require('autoprefixer')
                                ];
                            }
                        }
                    },
                    { loader: 'sass-loader' }
                ]
            },
            {
                test: /\.(jpe?g|png|gif|svg)$/i,
                loaders: [
                    'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
                    'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
                ]
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.ts']
    },
    plugins: [
        new BrowserSyncPlugin({
                host: 'localhost',
                port: 3000,
                proxy: 'http://localhost:3100/'
            },
            {
                reload: false
            }
        ),
        new HtmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
        }),
    ]
};

的package.json

{
"name": "translation",
  "version": "0.0.1",
  "description": "translations ( using i18n )",
  "main": "index.js",
  "scripts": {
    "start": "webpack --progress",
    "serve": "webpack-dev-server --progress"
  },
  "repository": {
    "type": "git",
    "url": "http://git.krakow.comarch/rnd/translation-i18n"
  },
  "author": "K.N.",
  "license": "ISC",
  "dependencies": {
    "@angular/animations": "^4.0.2",
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "5.0.1",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.1",
    "babel-preset-env": "^1.2.2",
    "browser-sync": "^2.18.8",
    "browser-sync-webpack-plugin": "^1.1.4",
    "css-loader": "^0.27.3",
    "html-webpack-plugin": "^2.28.0",
    "image-webpack-loader": "^3.3.0",
    "node-sass": "^4.5.2",
    "postcss-loader": "^1.3.3",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.16.1",
    "ts-loader": "^2.0.3",
    "typescript": "^2.2.2",
    "typings": "^2.1.0",
    "webpack": "^2.3.2",
    "webpack-dev-server": "^2.4.2"
  }
}

我不知道应该给你哪些文件。即使我不知道问题出在哪里..感谢您的帮助。

更新

我已将此端口添加到防火墙: enter image description here

道格尔尼意味着 - 任何 仍然不起作用 - 结果相同:C

1 个答案:

答案 0 :(得分:2)

如果您的应用已在localhost:8080,那么我相信您应该使用:

 new BrowserSyncPlugin({
            host: 'localhost',
            port: 3000,
            proxy: 'http://localhost:8080/'
        },