If you previously used Webpacker's extract_css to include Sass/SCSS files within JavaScript (e.g., import '../scss/application.scss'), you must manually configure mini-css-extract-plugin in your webpack.config.js after migrating to jsbundling-rails.
- Install dependencies:
yarn add mini-css-extract-plugin sass sass-loader css-loader - Configure
webpack.config.js with the plugin and loaders.
const path = require("path")
const webpack = require("webpack")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
module.exports = {
mode: "production",
devtool: "source-map",
entry: {
application: "./app/javascript/application.js"
},
resolve: {
modules: ["app/javascript", "node_modules"],
},
output: {
filename: "[name].js",
sourceMapFilename: "[file].map",
path: path.resolve(__dirname, "app/assets/builds"),
},
plugins: [
new MiniCssExtractPlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
],
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
],
},
}