Last active
December 20, 2017 05:19
-
-
Save praveenperera/febf6833d8e58c1e9d8f280e30ee5c62 to your computer and use it in GitHub Desktop.
Webpack 2.0+ with Phoenix 1.3+ (Elixir)
This file contains 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
import webpack from "webpack"; | |
import ExtractTextPlugin from "extract-text-webpack-plugin"; | |
import CopyWebpackPlugin from "copy-webpack-plugin"; | |
import WebpackNotifierPlugin from "webpack-notifier"; | |
import path from "path"; | |
const ENV = process.env.NODE_ENV || "development"; | |
const IS_PROD = ENV === "production"; | |
const OUTPUT_PATH = path.resolve(__dirname, "..", "priv", "static"); | |
const extractSass = new ExtractTextPlugin({ | |
filename: "css/app.css", | |
}); | |
export default { | |
entry: ["./css/app.scss", "./js/app.js"], | |
output: { | |
path: OUTPUT_PATH, | |
filename: "./js/app.js", | |
publicPath: "/", | |
}, | |
resolve: { | |
modules: ["node_modules", `${__dirname}/js`], | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
loader: "babel-loader", | |
include: __dirname, | |
}, | |
{ | |
test: /\.css$/, | |
use: [ | |
"style-loader", | |
{ | |
loader: "css-loader", | |
options: { | |
includePaths: [`${__dirname}/node_modules`], | |
sourceMap: true, | |
}, | |
}, | |
], | |
}, | |
{ | |
test: /\.scss$/, | |
use: extractSass.extract({ | |
use: [ | |
{ | |
loader: "css-loader", | |
options: { | |
includePaths: [`${__dirname}/node_modules`], | |
sourceMap: true, | |
}, | |
}, | |
"resolve-url-loader", | |
{ | |
loader: "sass-loader", | |
options: { | |
includePaths: [`${__dirname}/node_modules`], | |
sourceMap: true, | |
}, | |
}, | |
], | |
fallback: "style-loader", | |
}), | |
}, | |
{ | |
test: /\.(eot|svg|ttf|woff|woff2)$/, | |
loader: "file-loader", | |
options: { | |
name: "[name].[ext]", | |
outputPath: "./fonts", | |
publicPath: "../fonts/", | |
}, | |
}, | |
{ | |
test: /\.(jpg|png|gif)$/, | |
loader: "file-loader", | |
options: { | |
name: "[name].[ext]", | |
outputPath: "./images", | |
publicPath: "../images/", | |
}, | |
}, | |
], | |
}, | |
plugins: [ | |
new CopyWebpackPlugin([ | |
{ | |
from: `${__dirname}/static`, | |
to: OUTPUT_PATH, | |
ignore: [".DS_Store"], | |
}, | |
]), | |
new WebpackNotifierPlugin(), | |
new webpack.ProvidePlugin({ | |
$: "jquery", | |
jQuery: "jquery", | |
"window.jQuery": "jquery" | |
}), | |
extractSass, | |
], | |
}; |
package.json
"scripts": {
"deploy": "NODE_ENV=production webpack -p",
"watch": "webpack --watch-stdin --color"
}
dev.exs
watchers: [npm: ["run", "watch", cd: Path.expand("../", __DIR__)]]
.babelrc
{ "presets": ["latest", "react", "stage-0"] }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install all npm modules