Last active
June 1, 2019 20:37
-
-
Save Cervajz/63bc84de9ca362900e584f57c95438fe to your computer and use it in GitHub Desktop.
Bootstrap 4 in Phoenix Framework using Webpack
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
// We need to import the CSS so that webpack will load it. | |
// The MiniCssExtractPlugin is used to separate it out into | |
// its own CSS file. | |
import css from "../css/app.scss" | |
// webpack automatically bundles all modules in your | |
// entry points. Those entry points can be configured | |
// in "webpack.config.js". | |
// | |
// Import dependencies | |
// | |
import "phoenix_html" | |
import "bootstrap" | |
// Import local files | |
// | |
// Local files can be imported directly using relative paths, for example: | |
// import socket from "./socket" |
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
@import "~bootstrap/scss/bootstrap"; |
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
{ | |
"repository": {}, | |
"license": "MIT", | |
"scripts": { | |
"deploy": "webpack --mode production", | |
"watch": "webpack --mode development --watch" | |
}, | |
"dependencies": { | |
"autoprefixer": "^9.5.1", | |
"bootstrap": "^4.3.1", | |
"jquery": "^3.4.1", | |
"node-sass": "^4.12.0", | |
"phoenix": "file:../deps/phoenix", | |
"phoenix_html": "file:../deps/phoenix_html", | |
"popper.js": "^1.15.0", | |
"postcss-loader": "^3.0.0", | |
"precss": "^4.0.0", | |
"sass-loader": "^7.1.0", | |
"style-loader": "^0.23.1" | |
}, | |
"devDependencies": { | |
"@babel/core": "^7.0.0", | |
"@babel/preset-env": "^7.0.0", | |
"babel-loader": "^8.0.0", | |
"copy-webpack-plugin": "^4.5.0", | |
"css-loader": "^2.1.1", | |
"mini-css-extract-plugin": "^0.4.0", | |
"optimize-css-assets-webpack-plugin": "^4.0.0", | |
"uglifyjs-webpack-plugin": "^1.2.4", | |
"webpack": "4.4.0", | |
"webpack-cli": "^2.0.10" | |
} | |
} |
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 glob = require('glob'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
module.exports = (env, options) => ({ | |
optimization: { | |
minimizer: [ | |
new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }), | |
new OptimizeCSSAssetsPlugin({}) | |
] | |
}, | |
entry: { | |
'./js/app.js': ['./js/app.js'].concat(glob.sync('./vendor/**/*.js')) | |
}, | |
output: { | |
filename: 'app.js', | |
path: path.resolve(__dirname, '../priv/static/js') | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { loader: 'babel-loader' } | |
}, | |
{ | |
test: /\.scss$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
'css-loader', | |
{ | |
loader: 'postcss-loader', | |
options: { | |
plugins: function () { | |
return [ | |
require('precss'), | |
require('autoprefixer') | |
]; | |
} | |
} | |
}, | |
'sass-loader' | |
] | |
} | |
] | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({ filename: '../css/app.css' }), | |
new CopyWebpackPlugin([{ from: 'static/', to: '../' }]) | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment