Skip to content

Instantly share code, notes, and snippets.

@oal
Last active October 26, 2017 09:49
Show Gist options
  • Save oal/898df82fa64e54dd16d0 to your computer and use it in GitHub Desktop.
Save oal/898df82fa64e54dd16d0 to your computer and use it in GitHub Desktop.
Webpack config for Pixi.js using Babel.
'use strict';
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: './src/game.js',
output: {
filename: 'build/game.js'
},
node: {
fs: 'empty'
},
module: {
loaders: [
{
test: /\.json$/,
include: path.join(__dirname, 'node_modules', 'pixi.js'),
loader: 'json',
},
{
test: /\.js$/,
exclude: path.join(__dirname, 'node_modules'),
loader: 'babel'
}
]
}
};
@rvierich
Copy link

This will actually just create an empty module for fs. Once any function is called that uses fs (ex: AsciiFilter.js#L25), the fs module will be empty and you will hit an error.

To avoid this, you can dump the file contents that would normally be loaded from fs into a string inline within the js file. This can be done using a in a postLoader, brfs (browserify-fs), and transform-loader.

npm install brfs
npm install transform-loader

then add this to the webpack config:

postLoaders: [
  {
    test: /\.js$/,
    loader: 'transform/cacheable?brfs',
    include: /node_modules\/pixi\.js/
  }
]

@davydka
Copy link

davydka commented Jan 7, 2016

This is the most direct and simple example of configuring webpack with PIXI that I found.

https://gist.github.com/mjackson/ecd3914ebee934f4daf4

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