Skip to content

dev-server usage within vagrant #126

@plandolt

Description

@plandolt

I have troubles getting dev-server command working. While production and dev arguments work like expected and the assets being build correctly I do have troubles with dev-server.

My setup is a vagrant machine with virtualbox. I can access the vm by ip 172.16.23.10 or hostname (e.g. website.company.dev). So far, so good! Problem arises when I try to use dev-server within my vm (not on my local machine!). Here are my steps I already tried to make it working:

  1. run node_modules/.bin/encore dev-server. The output is:
    Running webpack-dev-server ...
    Content not from webpack is served from /vagrant
    404s will fallback to /index.html
    DONE Compiled successfully in 12873ms

Due tu the fact that the server within my vm is binding itself to 127.0.0.1:8080 I cant access it from my local machine. next try:

  1. run node_modules/.bin/encore dev-server --host 0.0.0.0. Same output as in my first try. But now the server within my vm is bind to 0.0.0.0:8080.

Now I can access the server from my local machine using my browser to request http://website.company.dev:8080. Now I get a Invalid Host header Response. next try:

  1. run node_modules/.bin/encore dev-server --host 0.0.0.0 --public website.company.dev. Same output as in my first try. I could als have used --disable-host-check option but I like to just set the hostname right. Browsing the site with http://website.company.dev:8080 now gives me the error I cant get around:

Cannot GET /

According to my nginx access logfile it doesn't even hit the underlying webserver at all to serve my site (not the assets). Accessing http://website.company.dev:8080/webpack-dev-server is showing me by build files:

fonts
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
glyphicons-halflings-regular.woff2
images
glyphicons-halflings-regular.svg
app.js
app (magic html for app.js) (webpack-dev-server)
main.css
manifest.json

What else ist there to say? I dont know why its not working. I'll post my config and dependency files to give you an overview on how I use encore. Any help or hints are much appreciated!

package.json

{
  "devDependencies": {
    "@symfony/webpack-encore": "^0.12.0",
    "bootstrap-sass": "^3.3.7",
    "jquery": "^3.2.1",
    "node-sass": "^4.5.3",
    "postcss-loader": "^2.0.6",
    "sass-loader": "^6.0.6"
  },
  "browserslist": [
    "last 2 version"
  ],
  "scripts": {
    "build": "webpack"
  }
}

webpack.config.js

var Encore = require('@symfony/webpack-encore');
Encore
    .setOutputPath('frontend/build/')
    .setPublicPath('/frontend/build')
    .cleanupOutputBeforeBuild()
    .addEntry('app', './frontend/assets/js/app.js')
    .addStyleEntry('main', './frontend/assets/scss/main.scss')
    .enableSassLoader(function(sassOptions) {}, {
        resolve_url_loader: false
    })
    .enablePostCssLoader()
    .autoProvidejQuery()
    .enableSourceMaps(!Encore.isProduction())
;

// export the final configuration
var config = Encore.getWebpackConfig();
config.watchOptions = { poll: true, ignored: /node_modules/ };
module.exports = config;

Btw: When running dev-server with host and public option the variable config.devServer holds this content:

devServer:
   { contentBase: '/vagrant',
     publicPath: 'http://0.0.0.0:8080/frontend/build/',
     headers: { 'Access-Control-Allow-Origin': '*' },
     hot: false,
     quiet: true,
     compress: true,
     historyApiFallback: true,
     watchOptions: { ignored: /node_modules/ },
     https: undefined }

As you can see from the webpack.config.js I use an app which has its front controller (index.php) in the project root (not in /web like symfony has). My assets are in /frontend/assets/(css|js) and the build files should go to /frontend/build/.

Big thank you for everyone kept reeding until the very end of this (long) issue I encounter! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions