wolfiton
Phoenix 1.4.11 how to use webpack with sass?
Hi everyone,
I need a simple configuration to add to the already webpack plugins added by phoenix by default to manage my sass.
Here is the default config
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env, options) => ({
optimization: {
minimizer: [
new TerserPlugin({ cache: true, parallel: true, sourceMap: false }),
new OptimizeCSSAssetsPlugin({})
]
},
entry: {
'./js/app.js': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
},
output: {
filename: 'app.js',
path: path.resolve(__dirname, '../priv/static/js')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
]
});
How can I make it to convert my sass from the vendor dir to go to the css dir?
Ex: /assets/vendors/bulma/bulma.sass => /assets/css/bulma/bulma.min.css ?
Thanks in advance
Marked As Solved
wolfiton
I started with this version for learning purposes because my interest is grapqhl and nuxt and I managed to find a config that works but wnated to try with a new biulma component to see if it really works.
Give me a couple a minutes and i should be able to push everything to github for future references for everybody.
Also thanks for the offer of sharing the config you have but i am good for now.
Update the repo is here https://github.com/wolfiton/blog_api it uses yarn and you can use the following command yarn watch
Also Liked
adamjarling
Here’s our webpack config for Sass using Phoenix v1.5.4 if it helps:
...
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: {} },
{ loader: "sass-loader", options: {} },
],
},
]
}
...
package.json includes node-sass and sass-loader packages in devDependencies
Then in /assets/styles/app.scss (entry file), we import all Sass files here:
@charset "utf-8";
// Custom variables go before importing Bulma
@import "~@nulib/admin-react-components/dist/public/styles/variables";
@import "~@nulib/admin-react-components/dist/public/styles/fonts";
@import "~bulma/bulma";
...
@import "./scss/mixins";
@import "./scss/base";
@import "./scss/reactivesearch";
@import "./scss/skeleton";
@import "./scss/hover";
kokolegorille
kokolegorille
No, I just wanted to tell sass files are not going to trigger scss rule.
You might try
test: /\.(sass|scss)$/,
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










