Skip to content

Doesn't write bundles inside build directory when using webpack 2 #46

@saeidalidadi

Description

@saeidalidadi

I am using webpack with the following config:

/**
 * Require Browsersync along with webpack and middleware for it
 */
var browserSync = require('browser-sync');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');

/**
 * Require ./webpack.config.js and make a bundler from it
 */
var webpackConfig = require('./webpack.dev.config');
var bundler = webpack(webpackConfig);
console.log(webpackConfig.output.publicPath);
/**
 * Run Browsersync and use middleware for Hot Module Replacement
 */
browserSync({
    server: {
      baseDir: 'app',

      middleware: [
        webpackDevMiddleware(bundler, {
          // IMPORTANT: dev middleware can't access config, so we should
          // provide publicPath by ourselves
          publicPath: webpackConfig.output.publicPath,

          // pretty colored output
          stats: { colors: true }

          // for other settings see
          // http://webpack.github.io/docs/webpack-dev-middleware.html
        }),

        // bundler should be the same as above
        webpackHotMiddleware(bundler)
      ]
    },

    // no need to watch '*.js' here, webpack will take care of it for us,
    // including full page reloads if HMR won't work
    files: [
      'app/css/*.css',
      'app/*.html'
    ]
});

webpack.dev.config.js

const path = require('path');
const webpack = require('webpack');
const phaserModule = path.join(__dirname, '/node_modules/phaser/');
const phaser = path.join(phaserModule, 'build/custom/phaser-split.js'),
  
  pixi = path.join(phaserModule, 'build/custom/pixi.js'),
  p2 = path.join(phaserModule, 'build/custom/p2.js');

module.exports = {
    //context: path.join(__dirname, 'app/src'),
    entry: {
      app: path.resolve(__dirname, 'app/src/app.js'),
      vendors: [
        'phaser',
        'webpack/hot/dev-server',
        'webpack-hot-middleware/client',
      ]
    },
    output: {
      publicPath: path.resolve(__dirname, 'app/build/'),
      path: path.resolve(__dirname, 'app/build'),
      filename: '[name].bundle.js'
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /(node_modules)/,
          use: [
            {
              loader: 'babel-loader',
              options: {
                presets: ['env', 'es2015'],
                cacheDirectory: true
              }
            }
          ],
          test: [/\pixi.js/, /\p2.js/],
          use: [
            {
              loader: 'script-loader'
            }
          ]
        }
      ]
    },
    resolve: {
      alias: {
        'phaser': phaser,
          'pixi.js': pixi,
          'p2': p2,
      }
    },
    plugins: [
      new webpack.optimize.CommonsChunkPlugin({
        name: 'vendors' // Specify the common bundle's name.
      }),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NoEmitOnErrorsPlugin()
    ],
    target: 'web'
}

When I do bundling with webpack cli its ok, but it doesnt load my bundles after bundling from node devserver.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions