Whats the purpose of assetsPluginProcessOutput?

Hi,

everytime I try to create a production of my sage-9 theme it fails:

webpack -d --progress --release

OUTPUT

TypeError: Path must be a string. Received { js: 'scripts/customizer_0fefe09edc473dfa8cef.js' }
    at assertPath (path.js:7:11)
    at Object.extname (path.js:1429:5)
    at Object.assetsPluginProcessOutput [as processOutput] (/Users/Kevin/webwork/burnaut/wpahri.dev/web/app/themes/mj/webpack.config.js:52:16)
    at ReadFileContext.callback (/Users/Kevin/webwork/burnaut/wpahri.dev/web/app/themes/mj/node_modules/assets-webpack-plugin/lib/output/createOutputWriter.js:43:30)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:359:13)

The code fails in the assetsPluginProcessOutput function:

webpack.config.js

if (path.extname(assets[name]) === '') { // << error

debug assets object: console.info(assets)

main: 
   { js: 'scripts/main_0fefe09edc473dfa8cef.js',
     css: 'styles/main_0fefe09edc473dfa8cef.css' } }
{ js: 'scripts/customizer_0fefe09edc473dfa8cef.js' }

I removed the processOutput option for the assets-webpack-plugin
and it works. So whats the downside of removing this?

  webpackConfig.plugins.push(new AssetsPlugin({
    path: path.join(__dirname, config.output.path),
    filename: 'assets.json',
    fullPath: false
    //processOutput: assetsPluginProcessOutput
  }));

EDIT:

Oh an here is my config.json

{
  "context": "assets",
  "entry": {
    "main": [
      "./scripts/main.js",
      "./styles/main.scss"
    ],
    "customizer": [
      "./scripts/customizer.js"
    ]
  },
  "output": {
    "path": "dist",
    "publicPath": "/app/themes/mj/dist/"
  },
  "devUrl": "http://wpahri.dev",
  "devPort": 3000
}

EDIT2:

If I add the js property it works:

if (path.extname(assets[name].js) === '') { // << error

EDIT3:

Shouldn’t the production output be just dist/scripts/main.js without hash?
You will get an 404 in the production build because you load main.js and main.css.

Regards Kevin

The purpose of production is to have hashed version of your bundles in order to leverage cache bursting.
Production also runs an additional level of optimization on your assets, removing comments, minifying and other things.

Currently the function is working fine on my environment though and I cannot replicate your error.

Hi,

EDIT: It’s working now. Here is the fix: https://github.com/roots/sage/issues/1659#issuecomment-223032889

Regards

1 Like

Awesome! Thank you for pointing it out!