Created
March 16, 2017 09:21
-
-
Save AleBles/73dea441e1c926f8924cdcf42e45333f to your computer and use it in GitHub Desktop.
Webpack config with OG plugins
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
const path = require('path'); | |
const webpack = require('webpack'); | |
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | |
// Phaser webpack config | |
const phaserModule = path.join(__dirname, './node_modules/phaser/'); | |
const phaser = path.join(phaserModule, 'build/custom/phaser-split.js'); | |
const pixi = path.join(phaserModule, 'build/custom/pixi.js'); | |
const p2 = path.join(phaserModule, 'build/custom/p2.js'); | |
//Orange games plugins conf | |
const orangeModule = path.join(__dirname, './node_modules/@orange-games/'); | |
const ads = path.join(orangeModule, 'phaser-ads/build/phaser-ads.js'); | |
const spine = path.join(orangeModule, 'phaser-spine/build/phaser-spine.js'); | |
const cache = path.join(orangeModule, 'phaser-cachebuster/build/phaser-cachebuster.js'); | |
const storage = path.join(orangeModule, 'phaser-super-storage/build/phaser-super-storage.js'); | |
const definePlugin = new webpack.DefinePlugin({ | |
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')) | |
}); | |
var env = process.argv[process.argv.length - 1]; | |
var version = 'dev'; | |
//Write versiom | |
const fs = require('fs'); | |
fs.writeFile("./js/version.js", "var version ='" + version + "';", function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("Version: " + version + " was written to file!"); | |
}); | |
var config = { | |
entry: { | |
app: [ | |
path.resolve(__dirname, './ts/app.ts') | |
], | |
vendor: ['pixi', 'p2', 'phaser', 'webfontloader','phaser-ads', 'phaser-spine', 'phaser-cachebuster', 'phaser-super-storage'] | |
}, | |
devtool: 'source-map', | |
output: { | |
pathinfo: true, | |
path: path.resolve(__dirname, './js'), | |
publicPath: './', | |
filename: 'og-fabrique-boilerplate.js' | |
}, | |
module: { | |
loaders: [ | |
//Typescript loader | |
{test: /\.tsx?$/, loader: 'ts-loader'}, | |
//Expose phaser modules | |
{test: /pixi\.js/, loader: 'expose?PIXI'}, | |
{test: /phaser\-split\.js$/, loader: 'expose?Phaser'}, | |
{test: /p2\.js/, loader: 'expose?p2'}, | |
//Expose orange modules | |
{test: /phaser\-ads\.js$/, loader: 'exports-loader?PhaserAds=true'}, | |
{test: /phaser\-spine\.js$/, loader: 'exports-loader?PhaserSpine=true'}, | |
{test: /phaser\-cachebuster\.js$/, loader: 'exports-loader?PhaserCachebuster=true'}, | |
{test: /phaser\-super\-storage\.js$/, loader: 'exports-loader?PhaserSuperStorage=true'} | |
] | |
}, | |
node: { | |
fs: 'empty', | |
net: 'empty', | |
tls: 'empty' | |
}, | |
resolve: { | |
alias: { | |
'phaser': phaser, | |
'pixi': pixi, | |
'p2': p2, | |
'phaser-ads': ads, | |
'phaser-spine': spine, | |
'phaser-cachebuster': cache, | |
'phaser-super-storage': storage | |
}, | |
extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] | |
} | |
}; | |
if (env === 'dev') { | |
config.watch = true; | |
config.plugins = [ | |
definePlugin, | |
new webpack.optimize.CommonsChunkPlugin(/* chunkName= */'vendor', /* filename= */'vendor.bundle.js', Infinity), | |
new BrowserSyncPlugin({ | |
host: process.env.IP || 'localhost', | |
port: process.env.PORT || 3000, | |
server: { | |
baseDir: ['./node_modules', './'] | |
} | |
}) | |
]; | |
} else { | |
config.plugins = [ | |
definePlugin, | |
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), | |
new webpack.optimize.UglifyJsPlugin({ | |
drop_console: true, | |
minimize: true, | |
output: { | |
comments: false | |
}, | |
compress: { | |
warnings: false | |
} | |
}), | |
new webpack.optimize.OccurenceOrderPlugin(), | |
new webpack.optimize.DedupePlugin() | |
]; | |
} | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment