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

bundled js cannot be found from webpack-dev-server invoked from gulp. #645

Closed
ghost opened this Issue Oct 11, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@ghost
Copy link

ghost commented Oct 11, 2016

webpack.config.js

  var path = require("path");
  module.exports = {
    entry: './src/app.ts',
    output: {
      path: path.resolve(__dirname, "dist"),
      filename: "bundle.js",
      publicPath: '/dist/'
    },
    devtool: "source-map",
    resolve: {
      // Add `.ts` and `.tsx` as a resolvable extension.
      extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
    },
    module: {
      loaders: [
        // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
        {
          test: /\.tsx?$/,
          loader: 'ts-loader'
        }
      ],
      preLoaders: [{
        test: /\.js$/,
        loader: "source-map-loader"
      }]
    }
  }

gulp task

import gulp from 'gulp';
import gutil from 'gutil';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import webpackConfig from '../webpack.dev.config.js';

gulp.task("webpack-dev-server", function(callback) {
  var myConfig = Object.create(webpackConfig);
  myConfig.devtool = "eval";
  myConfig.debug = true;
  myConfig.output.path = __dirname;
  myConfig.output.filename = 'dist/bundle.js';
  // Start a webpack-dev-server
  new WebpackDevServer(webpack(myConfig), {
    stats: {
      colors: true
    },
    hot: true
    // historyApiFallback: true,
    // publicPath: myConfig.output.publicPath /* '/dist/' */
  }).listen(8080, "localhost", function(err) {
    if (err) throw new gutil.PluginError("webpack-dev-server", err);
    gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
  });
});

wehen run gulp webpack-dev-server no error but cannot fount bundle.js

cmd output:

➜  gulp-webpack git:(master) ✗ gulp webpack-dev-server
[12:00:18] Requiring external module babel-register
[12:00:19] Using gulpfile ~/code_repositories/git/Coding/gulp-webpack/gulpfile.babel.js
[12:00:19] Starting 'webpack-dev-server'...
[webpack-dev-server] : http://localhost:8080/webpack-dev-server/index.html
ts-loader: Using typescript@2.0.3 and /Users/admin/code_repositories/git/Coding/gulp-webpack/tsconfig.json
Hash: e54fc54ee6598ab27cca
Version: webpack 1.13.2
Time: 1399ms
          Asset     Size  Chunks             Chunk Names
    bundleww.js  1.68 kB       0  [emitted]  main
bundleww.js.map  1.81 kB       0  [emitted]  main
chunk    {0} bundleww.js, bundleww.js.map (main) 151 bytes [rendered]
    [0] ./src/app.ts 151 bytes {0} [built]
webpack: bundle is now VALID.

@SpaceK33z SpaceK33z added the question label Oct 11, 2016

@SpaceK33z

This comment has been minimized.

Copy link
Member

SpaceK33z commented Oct 11, 2016

What exactly are you trying to do here? The bundle should be available under http://localhost:8080/dist/bundle.js, have you tried that?

Also, as the issue template said, please ask those kind of questions on Stack Overflow. You'll get better help there.

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Oct 11, 2016

after run gulp webpack-dev-server

cannot fount bundle.js in my workdir and http://localhost:8080/dist/bundle.js return 404

@SpaceK33z

This comment has been minimized.

Copy link
Member

SpaceK33z commented Oct 11, 2016

webpack-dev-server will not put your bundle.js in your workdir, it will compile your files in-memory. I just now notice that you have commented out this part:

// publicPath: myConfig.output.publicPath /* '/dist/' */

Can you try changing that to publicPath: '/dist/'?

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Oct 11, 2016

thanks ,
it is my fault.
http://localhost:8080/bundle.js it is work.

@SpaceK33z SpaceK33z closed this Oct 11, 2016

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Oct 11, 2016

thanks ,

“webpack-dev-server will not put your bundle.js in your workdir, it will compile your files in-memory”

notice myself

@LeTranAnhVu

This comment has been minimized.

Copy link

LeTranAnhVu commented Feb 15, 2019

Hi. So how can we make the bundle show up in disk instead build in memory? Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment