WestKeys

WestKeys

Every time I run mix phx.server, I get:

[info] Running HelloWeb.Endpoint with cowboy 2.8.0 at 0.0.0.0:4000 (http)
[info] Access HelloWeb.Endpoint at http://localhost:4000

webpack is watching the files…

[hardsource:86c17673] Using 1 MB of disk space.
[hardsource:86c17673] Tracking node dependencies with: package-lock.json.
[hardsource:86c17673] Reading from cache 86c17673...
Hash: 97fd47bb7gfde75674c1
Version: webpack 4.41.5
Time: 174ms
Built at: 2021-02-05 2:42:46 p.m.
                Asset       Size  Chunks             Chunk Names
       ../css/app.css   10.7 KiB     app  [emitted]  app
       ../favicon.ico   1.23 KiB          [emitted]
../images/phoenix.png   13.6 KiB          [emitted]
        ../robots.txt  202 bytes          [emitted]
               app.js   13.5 KiB     app  [emitted]  app
Entrypoint app = ../css/app.css app.js
[0] multi ./js/app.js 28 bytes {app} [built]
    + 5 hidden modules

Any way to control the output of this command?

Like in the docs:

$ mix phx.server
[info] Running HelloWeb.Endpoint with cowboy 2.5.0 at http://localhost:4000

Webpack is watching the files…
...

Showing Posts 9 to 1

derek-zhou

derek-zhou

I fully agree; and that’s why we need to be extra diligent in choosing a technology; not just go blindly with the status quo.

derek-zhou

derek-zhou

I understand. My knowledge about js tooling is even less then elixir; so my top priority for the js tooling is stay out of my way. Sadly, webpack failed this criteria for me.

dimitarvp

dimitarvp

JS fatigue is very real for everyone who’s not a JS dev – but has to deal with the frontend somewhat.

I’m glad that the JS community is working on improving the ecosystem but their expectations that everybody else should just keep up with what’s used nowadays is unrealistic.

To make things worse, they don’t give a single thought to backwards compatibility and transferable knowledge.

WestKeys

WestKeys OP

There is also vite that is competing in this space but js FaTiGuE. Much rather configure stock phoenix than go back down that rabbit hole

WestKeys

WestKeys OP

Silly me imagined for some reason Phoenix had some flags for this.

Updated my webpack.config.js and now works as expected:

Final result

❯ mix phx.server
[info] Running HelloWeb.Endpoint with cowboy 2.8.0 at 0.0.0.0:4000 (http)
[info] Access HelloWeb.Endpoint at http://localhost:4000

webpack is watching the files…

webpack.config.js

❯ cat assets/webpack.config.js
const path = require('path');
const glob = require('glob');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = (env, options) => {

  const devMode = options.mode !== 'production';

  return {
    stats: 'minimal',  #<-------Add kv------->
    optimization: {
      minimizer: [
        new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
        new OptimizeCSSAssetsPlugin({})
      ]
    },
    entry: {
      'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
    },
    output: {
      filename: '[name].js',
      path: path.resolve(__dirname, '../priv/static/js'),
      publicPath: '/js/'
    },
    devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader'
          }
        },
        {
          test: /\.[s]?css$/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
            'sass-loader',
          ],
        }
      ]
    },
    plugins: [
      new MiniCssExtractPlugin({ filename: '../css/app.css' }),
      new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
    ]
    .concat(devMode ? [new HardSourceWebpackPlugin({
      #<-------Add obj------->
      info: {
        level: 'warn'
      }  
    })] : [])
  }
};
derek-zhou

derek-zhou

It is very simple. Just install snowpack using the npm, than make a small snowpack.config.js:

module.exports = {
    mount: {
        "static": {url: "/", static: true, resolve: false},
        "css": "/css",
        "js": "/js"
    },
    plugins: [
        "@snowpack/plugin-postcss"
    ],
    buildOptions: {
        out: "../priv/static"
    },
};

then hook up snowpack into the flow. My way is chaning the package.json to:

...
  "scripts": {
    "deploy": "snowpack build",
    "watch": "snowpack build --watch"
  },
...

then in your dev.exs:

...
  watchers: [
    npm: [
      "run",
      "watch",
      cd: Path.expand("../assets", __DIR__)
    ]
...

In your template, make sure your js file is included with type=“module”, such as:

<script defer type="module" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>

The thing I like the most about snowpack is it does not bundle. All js files are loose, so it is much more easier to debug in the browser dev tool.

dimitarvp

dimitarvp

Is there a good guide on switching from webpack to snowpack in Phoenix projects?

derek-zhou

derek-zhou

try snowpack. It’s output is much more civil:

> @ watch /home/derek/projects/roastidious/assets
> snowpack build --watch

[snowpack] ! building source files...
[snowpack] ✔ build complete [2.83s]
[snowpack] ! installing dependencies...
[snowpack] ✔ install complete! [2.16s]
[snowpack] ! verifying build...
[snowpack] ✔ verification complete [0.00s]
[snowpack] ! writing build to disk...
[snowpack] Watching for changes...
...
[snowpack] File changed...
[debug] Live reload: priv/static/js/app.js
hauleth

hauleth

Which part you want to get rid of? Elixir logging can be controlled via setting appropriate level and for Webpack messages you need to check Webpack documentation.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews