Skip to content

Instantly share code, notes, and snippets.

@rclayton-the-terrible
Last active April 27, 2016 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rclayton-the-terrible/abb9389ac78b71dce92976fefa94735e to your computer and use it in GitHub Desktop.
Save rclayton-the-terrible/abb9389ac78b71dce92976fefa94735e to your computer and use it in GitHub Desktop.
Elixir+Phoenix and Webpack
use Mix.Config
# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :myapp, MyApp.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/.bin/webpack", "--watch", "--colors", "--progress"]]
# Watch static and templates for browser reloading.
config :myapp, MyApp.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
]
]
# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
# Set a higher stacktrace during development.
# Do not configure such in production as keeping
# and calculating stacktraces is usually expensive.
config :phoenix, :stacktrace_depth, 20
# Configure your database
config :myapp, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "myapp_dev",
hostname: "localhost",
pool_size: 10
// Bridges the Phoenix Channels system with Redux.
import {Socket} from 'phoenix'
import {eventReceived} from './action-creators.jsx';
let socket = new Socket('/socket', {params: {token: window.userToken}})
socket.connect()
let eventsChannel = socket.channel('events:all', {})
eventsChannel.join()
.receive('ok', resp => {
console.log('Got event', resp)
})
.receive('error', resp => {
console.warn('Got an error', resp)
})
let storeBinder = function(store){
eventsChannel.on('update', event => {
store.dispatch(eventReceived(event))
})
}
export default storeBinder;
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var env = process.env.MIX_ENV || 'dev';
var isProduction = (env === 'prod');
var plugins = [
new ExtractTextPlugin('app.css'),
new CopyWebpackPlugin([
{ from: './web/static/assets' },
{ from: './deps/phoenix_html/web/static/js/phoenix_html.js',
to: 'js/phoenix_html.js' }
])
];
// This is necessary to get the sass @import's working
var stylePathResolves = (
'includePaths[]=' + path.resolve('./') + '&' +
'includePaths[]=' + path.resolve('./node_modules')
);
if (isProduction) {
plugins.push(new webpack.optimize.UglifyJsPlugin({minimize: true}));
}
module.exports = {
entry: './web/static/js/app.js',
output: {
path: './priv/static/js',
filename: 'app.js'
},
resolve: {
alias: {
phoenix: __dirname + '/deps/phoenix/web/static/js/phoenix.js'
}
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style',
'css' + '!sass?outputStyle=expanded&' + stylePathResolves
)
},
// Inlining not working
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192'
},
{
test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&minetype=application/font-woff"
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&minetype=application/octet-stream"
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: "file"
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&minetype=image/svg+xml"
}
]
},
plugins: plugins
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment