Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
app
bin
config
lib
log
public
tmp
vendor
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru
package-lock.json
package.json
webpack.config.js

README.md

Simpacker sass example

Install packages

$ npm install --save-dev node-sass sass-loader css-loader mini-css-extract-plugin

Edit webpack config

 const path = require("path");
 const WebpackAssetsManifest = require("webpack-assets-manifest");
+const MiniCssExtractPlugin = require("mini-css-extract-plugin");

 const { NODE_ENV } = process.env;
 const isProd = NODE_ENV === "production";
@@ -18,5 +19,18 @@
   resolve: {
     extensions: [".js"]
   },
-  plugins: [new WebpackAssetsManifest({ publicPath: true })]
+  module: {
+    rules: [
+      {
+        test: /\.scss$/,
+        use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
+      }
+    ]
+  },
+  plugins: [
+    new WebpackAssetsManifest({ publicPath: true }),
+    new MiniCssExtractPlugin({
+      filename: isProd ? "[name]-[hash].css" : "[name].css"
+    })
+  ]
 };

Edit scripts

app/javascript/application.js

 import { hello } from "./greeter";
+import "./application.scss";

app/javascript/application.scss

$main-color: tomato;

body {
  color: $main-color;
}

app/views/layouts/application.html.erb

+    <%= stylesheet_pack_tag 'application' %>
     <%= javascript_pack_tag 'application' %>
You can’t perform that action at this time.