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

Imported node modules are ignored #146

Open
thany opened this issue Mar 24, 2017 · 1 comment
Open

Imported node modules are ignored #146

thany opened this issue Mar 24, 2017 · 1 comment

Comments

@thany
Copy link

thany commented Mar 24, 2017

When calling webpack from gulp, imported node modules are ignored. When I call webpack from the commandline, node modules are bundled absolutely fine.

In my script, I'm simply including import Vue from 'vue'; after having done a npm i --save vue. Then, in my webpack.config.js:

var path = require("path");

module.exports = {
  entry: "./app/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "app")
  },
  resolve: {
    alias: {
      vue: "vue/dist/vue.esm.js"
    }
  },
  devtool: "cheap-module-source-map"
};

When I run webpack (just like that) it bundles vue with my index.js. Life's good. Output is like so:

Hash: 18d4492d10b9af9c640d
Version: webpack 2.2.0
Time: 272ms
        Asset    Size  Chunks                    Chunk Names
    bundle.js  256 kB       0  [emitted]  [big]  main
bundle.js.map  314 kB       0  [emitted]         main
   [0] ./~/vue/dist/vue.esm.js 246 kB {0} [built]
   [1] ./~/process/browser.js 5.3 kB {0} [built]
   [2] (webpack)/buildin/global.js 509 bytes {0} [built]
   [3] ./app/index.js 131 bytes {0} [built]

Looks good.

Now, I install webpack-stream. And include this in my Gulpfile:

gulp.task("build", function() {
  return gulp.src("app/index.js")
    .pipe(webpack(
      require('./webpack.config.js')
    ))
    .pipe(gulp.dest("app/"));
});

Couldn't be simpler. However, in the resulting bundle.js, vue is not not only ignored, the import directive is left in as well, causing browsers to choke on it. Output is like so:

[17:17:53] Using gulpfile d:\test\gulpfile.js
[17:17:53] Starting 'build'...
[17:17:53] Version: webpack 1.14.0
        Asset     Size  Chunks             Chunk Names
    bundle.js  1.56 kB       0  [emitted]  main
bundle.js.map  1.79 kB       0  [emitted]  main
[17:17:53] Finished 'build' after 216 ms

So Vue was never bundled. Why?

@joppuyo
Copy link

joppuyo commented Apr 12, 2017

It looks like webpack-stream is not compatible with webpack2 using the default settings. I found success fixing this issue by following the instructions here and explicitly passing the webpack2 instance to webpack-stream like this:

var gulp = require('gulp');
var webpackStream = require('webpack-stream');
var webpack2 = require('webpack');

gulp.task('default', function() {
  return gulp.src('src/entry.js')
    .pipe(webpackStream({/* options */}, webpack2))
    .pipe(gulp.dest('dist/'));
});

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

2 participants