Skip to content

Instantly share code, notes, and snippets.

@ecpplus
Created October 4, 2016 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecpplus/c2196381c26d02241bc060ce2a8601da to your computer and use it in GitHub Desktop.
Save ecpplus/c2196381c26d02241bc060ce2a8601da to your computer and use it in GitHub Desktop.
Phoenix Framework webpack config example
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const config = {
devtool: "source-map",
entry: {
"app": ["./web/static/css/app.sass", "./web/static/js/app.js"],
},
output: {
path: "./priv/static",
filename: "js/app.js"
},
resolve: {
modulesDirectories: [ "node_modules", __dirname + "/web/static/js" ]
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel",
query: {
presets: ['react', 'es2015']
}
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract("style", "css")
}, {
test: /\.(scss|sass)$/,
loader: ExtractTextPlugin.extract(
"style",
"css!sass?includePaths[]=" + __dirname + "/node_modules"
)
}
]
},
devtool: ['cheap-module-source-map'],
plugins: [
new ExtractTextPlugin("css/app.css"),
new CopyWebpackPlugin([{ from: "./web/static/assets" }]),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}
}),
],
postcss: () => {
return [autoprefixer({
browsers: ['last 2 versions']
})];
}
}
if (process.env.NODE_ENV === 'production') {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false,
}
})
)
} else {
config.devtool = "#cheap-module-source-map"
}
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment