wolfiton

wolfiton

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

Showing Posts 1 to 10

wolfiton

wolfiton OP

So found this after searching with google for pheonix 1.4 sass

Hopefully it will fix my problem

wolfiton

wolfiton OP

Update no go with the config in post2#

My current config that doesn’t work

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"],
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          "sass-loader"
          // {
          //   loader: "postcss-loader",
          //   options: {
          //     config: {
          //       path: __dirname + "/postcss.config.js"
          //     }
          //   }
          // }
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({ filename: "../css/app.css" }),
    new CopyWebpackPlugin([{ from: "static/", to: "../" }])
  ]
});

Made a repo on github here with all my files maybe someone can help me because i can’t understand why it doesn’t work(confused)
Github Code

Error

ERROR in ./css/app.scss
Module build failed: ModuleBuildError: Module build failed: TypeError: this.getResolve is not a function
    at Object.loader (/home/dan/Codes/blog_api/assets/node_modules/sass-loader/dist/index.js:52:26)
    at /home/dan/Codes/blog_api/assets/node_modules/webpack/lib/NormalModule.js:244:20
    at /home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at runSyncOrAsync (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at Array.<anonymous> (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/home/dan/Codes/blog_api/assets/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /home/dan/Codes/blog_api/assets/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /home/dan/Codes/blog_api/assets/node_modules/graceful-fs/graceful-fs.js:115:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)
 @ ./js/app.js 4:0-34
 @ multi ./js/app.js
Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!node_modules/sass-loader/dist/cjs.js!css/app.scss:
    Entrypoint mini-css-extract-plugin = *
    [./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./css/app.scss] 186 bytes {mini-css-extract-plugin} [built] [failed] [1 error]
    
    ERROR in ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./css/app.scss
    Module build failed: TypeError: this.getResolve is not a function
        at Object.loader (/home/dan/Codes/blog_api/assets/node_modules/sass-loader/dist/index.js:52:26)
kokolegorille

kokolegorille

sass != scss

so bulma.sass will not trigger scss rule in webpack.

wolfiton

wolfiton OP

I am sorry but I can’t understand what you are trying to say.
Are you trying to tell me to change this

test: /\.scss$/

to this

test: /sass != scss/?
kokolegorille

kokolegorille

No, I just wanted to tell sass files are not going to trigger scss rule.

You might try

test: /\.(sass|scss)$/,
wolfiton

wolfiton OP

Thanks i will try this and come back with the results

wolfiton

wolfiton OP

Also if you can help me with postcss to make it work I would really appreciate it.After the sass loader config works

Error again using test: /.(sass|scss)$/

ERROR in ./css/app.scss
Module build failed: ModuleBuildError: Module build failed: TypeError: this.getResolve is not a function
    at Object.loader (/home/dan/Codes/blog_api/assets/node_modules/sass-loader/dist/index.js:52:26)
    at /home/dan/Codes/blog_api/assets/node_modules/webpack/lib/NormalModule.js:244:20
    at /home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at runSyncOrAsync (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at Array.<anonymous> (/home/dan/Codes/blog_api/assets/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/home/dan/Codes/blog_api/assets/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /home/dan/Codes/blog_api/assets/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /home/dan/Codes/blog_api/assets/node_modules/graceful-fs/graceful-fs.js:115:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)
 @ ./js/app.js 4:0-34
 @ multi ./js/app.js
Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!node_modules/sass-loader/dist/cjs.js!css/app.scss:
    Entrypoint mini-css-extract-plugin = *
    [./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./css/app.scss] 186 bytes {mini-css-extract-plugin} [built] [failed] [1 error]
    
    ERROR in ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./css/app.scss
    Module build failed: TypeError: this.getResolve is not a function
        at Object.loader (/home/dan/Codes/blog_api/assets/node_modules/sass-loader/dist/index.js:52:26)

wolfiton

wolfiton OP

So changed to this test: /\.(s *)css$ /

But get this error

ERROR in ./css/app.scss
Module parse failed: Unexpected character '@' (3:0)
You may need an appropriate loader to handle this file type.
| /* This file is for your main application css. */
| 
| @import "./bulma.sass";
| 
 @ ./js/app.js 4:0-34
 @ multi ./js/app.js

Can’t I import sass files in scss files?

Also thank you to everyone that helps me in advance with this config and errors

Update found this but doesn’t work for me

Also i have a loader for sass so why does a loader error pops up?

wolfiton

wolfiton OP

Works but with errors for bulma

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: /\.s?css$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          {
            loader: "postcss-loader",
            options: {
              config: {
                path: __dirname + "/postcss.config.js"
              }
            }
          },
          "fast-sass-loader"
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({ filename: "../css/app.css" }),
    new CopyWebpackPlugin([{ from: "static/", to: "../" }])
  ]
});

Error

ERROR in ./css/app.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src??ref--5-2!./node_modules/fast-sass-loader/lib!./css/app.scss)
    Module build failed (from ./node_modules/fast-sass-loader/lib/index.js):
    Error: media query expression must begin with '('
        at options.error (/home/dan/Codes/blog_api/assets/node_modules/node-sass/lib/index.js:291:26)
wolfiton

wolfiton OP

Has someone experienced something similar with the problem i am having here?

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews