Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 Stream won't compile #248

Open
dgoring opened this issue Jan 4, 2023 · 1 comment
Open

Webpack 5 Stream won't compile #248

dgoring opened this issue Jan 4, 2023 · 1 comment

Comments

@dgoring
Copy link

dgoring commented Jan 4, 2023

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
Copy link
Author

dgoring commented Jan 4, 2023

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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant