Created
November 11, 2014 08:36
-
-
Save nesheroj/7cbf14c18af38294b648 to your computer and use it in GitHub Desktop.
webpack & phaser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var path = require("path"); | |
var webpack = require("webpack"); | |
var isDirectory = function (file) { | |
return fs.statSync(path.join('./src/games/', file)).isDirectory(); | |
}; | |
var entries = { | |
gamenginename: "./gamenginename/main.js", | |
vendor: [ | |
"bluebird", | |
"jquery", | |
"phaser", | |
"phaser-debug" | |
] | |
}; | |
fs.readdirSync('./src/games/').filter(isDirectory).forEach(function (game) { | |
entries['games/' + game] = './games/' + game + '/main.js'; | |
}); | |
module.exports = { | |
cache: true, | |
context: path.join(__dirname, "src"), | |
entry: entries, | |
output: { | |
path: path.join(__dirname, "dist"), | |
publicPath: "/", | |
filename: "[name]/game.js?[hash]" | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.js$/i, exclude: /node_modules/i, loader: 'traceur?experimental' }, | |
{ test: /(phaser-arcade-physics|phaser-debug)\.js$/i, loader: 'script' }, | |
{ test: /\.json$/i, loader: "json-loader" }, | |
{ test: /\.less$/i, loader: "style-loader!css-loader!less-loader" }, | |
{ test: /\.(jpe?g|png|gif)$/i, loader: "file?name=[path][name].[ext]?[hash]" }, | |
{ test: /\.(mp3|ac3|ogg|m4a)$/i, loader: "file?name=[path][name].[ext]?[hash]" }, | |
{ test: /\.(ttf|woff|eot)$/i, loader: "file?name=[path][name].[ext]?[hash]" } | |
] | |
}, | |
resolve: { | |
alias: { | |
"jquery": path.join(__dirname, "node_modules/jquery/dist/jquery.js"), | |
"phaser": path.join(__dirname, "node_modules/phaser/dist/phaser-arcade-physics.js"), | |
"phaser-debug": path.join(__dirname, "node_modules/phaser-debug/dist/phaser-debug.js") | |
}, | |
extensions: ["", ".js"] | |
}, | |
plugins: [ | |
new webpack.optimize.CommonsChunkPlugin("gamenginename", "libs/gamenginename.js?[hash]"), | |
new webpack.optimize.CommonsChunkPlugin("vendor", "libs/gamenginename.vendor.js?[hash]"), | |
new webpack.ProvidePlugin({ | |
$: "jquery", | |
Promise: "bluebird" | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you load Phaser in modules? I cannot make it work. Or could you please share working example? Thanks