S
S
Sergey Burduzha2021-12-15 13:55:55
Laravel
Sergey Burduzha, 2021-12-15 13:55:55

How to make mix for laravel run through docker work?

Good afternoon.
When I installed laravel locally, and I work in ubuntu, then I set the host address itself, for example laravel.local
Now I run laravel as npm run watch

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "mix --production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "browser-sync": "^2.27.7",
        "browser-sync-webpack-plugin": "^2.3.0",
        "cross-env": "^7.0",
        "jquery": "^3.2",
        "laravel-mix": "^6.0.39",
        "lodash": "^4.17.19",
        "popper.js": "^1.12",
        "postcss": "^8.4.4",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.20.1",
        "sass-loader": "^12.4.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10",
        "webpack": "^5.3.1",
        "webpack-livereload-plugin": "^1.2.0"
    }
}


In webpack.mix.js
const mix = require('laravel-mix');
let productionSourceMaps = false;

mix.setPublicPath('public/build')
    .setResourceRoot('build')
    .js('resources/js/app.js', 'js')
    .sass('resources/sass/app.scss', 'css')
    .version()
    .options({
        processCssUrls: false
    })
    .sourceMaps(productionSourceMaps, 'source-map')
    .browserSync({
        proxy: 'https://localhost:8088/',
        files: [
            'public/build/css/app.css',  // Generated .css file
            'public/build/js/app.js',    // Generated .js file
            'public/**/*.+(html|php)',          // Generic .html and/or .php files [no specific platform]
            'app/**/*.+(html|php)',          // Generic .html and/or .php files [no specific platform]
            'resources/views/**/*.php', // Laravel-specific view files
        ],
        notify: {
            styles: {
                top: 'auto',
                bottom: '0'
            }
        },
        open: false
    });


in the proxy, I will prescribe the site address, and then, when I change php, css or js in the code, then my page will reload itself.

And now I started learning docker.
Launched the site and it works.
The address is localhost:8088

Only when I run the site from the container via mix
docker-compose exec node npm run watch

node - the name of the container where node.js

webpack compiled successfully
[Browsersync] Proxying: https://localhost:8088
[Browsersync] Access URLs:
 ------------------------------------
       Local: https://localhost:3000
    External: https://172.18.0.3:3000
 ------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 ------------------------------------
[Browsersync] Watching files...


And nothing opens at https://localhost:3000 .

I also have ssl connected.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Starkov, 2021-12-15
@serii81

It is possible to run npm on the host system, past docker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question