shama / webpack-stream

:tropical_drink: Run webpack through a stream interface
MIT License
1.39k stars 122 forks source link

Webpack 5 Stream won't compile #248

Open dgoring opened 1 year ago

dgoring commented 1 year ago

I can't seem to get this to compile a file stream with webpack 5

webpack 4 works fine, on my current node version (16) but I need to update to node 18 and must update to webpack 5

gulpfile.js

const WP_THEME = 'bespoke-theme';
const THEMEPATH = 'public/content/themes/' + WP_THEME;

/* Needed gulp config */
const { series, src, dest, watch }  = require('gulp');
const sass        = require('gulp-sass')(require('node-sass'));
const env         = require('minimist')(process.argv.slice(2));
const named       = require('vinyl-named');
const uglify      = require('gulp-uglify-es').default;
const plumber     = require('gulp-plumber');
const webpack     = require('webpack-stream');

/* javascripts task */
async function javascript ()
{
  var scripts = src([
    THEMEPATH + '/assets/javascript/main.js'
  ])
    .pipe(plumber())
    .pipe(named())
    .pipe(webpack({
      mode: env.production ? 'production' : 'development',
      externals: {
        jquery: 'jQuery',
      },
    }));

  if(env.production)
  {
    scripts = scripts.pipe(uglify());
  }

  return scripts
    .pipe(dest(THEMEPATH + '/dist/js'));
}

exports.javascript  = javascript;

package.json

{
  "private": true,
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "devDependencies": {
    "gulp": "^4.0.1",
    "gulp-css-useref": "^0.0.1",
    "gulp-cssmin": "^0.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-resolve-url": "^0.0.2",
    "gulp-sass": "^5.0",
    "gulp-sourcemaps": "^3.0",
    "gulp-uglify-es": "^3.0",
    "minimist": "^1.2.7",
    "vinyl-named": "^1.1.0",
    "vinyl-source-stream": "^2.0",
    "node-sass": "^6.0.1",
    "webpack-stream": "^7.0",
    "webpack": "^5.75"
  },
  "dependencies": {
    "bootstrap": "^5.1",
    "@fortawesome/fontawesome-free": "^6.1.0",
    "jquery": "^3.2.1",
    "@popperjs/core": "^2.10.2"
  },
  "scripts": {
    "dev": "gulp",
    "development": "gulp",
    "watch": "gulp watch",
    "production": "gulp --production"
  }
}
dgoring commented 1 year ago

It seems that if i take all "require"'s out of the target file it compiles but don't work without those libraries

The stream isn't providing any helpful errors

main.js

window.$ = window.jQuery = require('jquery/src/jquery');

import * as bootstrap from 'bootstrap';