shama / webpack-stream

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

Webpack stream w/ Gulp — errors when using aliases in webpack config #249

Closed mrfsrf closed 1 year ago

mrfsrf commented 1 year ago

Issue with webpack-stream not resolving aliases in webpack.config.js. I should mention that I'm using Gulp alongside web pack-stream.

Part of webpack.config.js:

 ...
  resolve: {
    extensions: ['.js'],
    alias: {
      Bootstrap: path.resolve(__dirname, 'node_modules/bootstrap/js/src/'),
      Swiper: path.resolve(__dirname, 'node_modules/swiper/dist/js/'),
      Popper: path.resolve(__dirname, 'node_modules/@popper/dist/esm/'),
    },
  },

Gulp Task:


const webpackStream = require('webpack-stream'); // version ^7.0.0
const named = require('vinyl-named'); // version ^1.1.0
const { src, dest } = require('gulp'); // version ^4.0.2

const webPack = () => {
  return src(`${paths.scripts.src}/main.js`)
    .pipe(named())
    .pipe(webpackStream(require('../webpack.config.js')))
    .pipe(dest(`${paths.scripts.dest}`));
}

Errors

Error in plugin "webpack-stream"
Message:
Module not found: Error: Can't resolve 'Swiper/swiper' in '/..../src/js/test'
Module not found: Error: Can't resolve 'Bootstrap/popover' in '/..../src/js/test'
mrfsrf commented 1 year ago

Closing this since the issue was in the webpack.config generated from npx, which had additional logic for isProduction and such. Just exported config directly and that solved the issue.