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

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

Open
saeidalidadi opened this issue Mar 14, 2017 · 0 comments
Open

Comments

@saeidalidadi
Copy link

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

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