apalfrey / select2-bootstrap-5-theme

A Select2 v4 theme for Bootstrap 5
https://apalfrey.github.io/select2-bootstrap-5-theme/
MIT License
212 stars 48 forks source link

Build error with webpack/sass-loader of modern Sass JS API #91

Open taketo1113 opened 2 weeks ago

taketo1113 commented 2 weeks ago

When use webpack/sass-loader of modern Sass JS API, it raise build error with can't find a scss path of bootstrap package.

Steps to reproduce:

Can't find stylesheet to import.
  ╷
5 │ @import "node_modules/bootstrap/scss/functions";
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  node_modules/select2-bootstrap-5-theme/src/select2-bootstrap-5-theme.scss 5:9  @import
  _path_/application.scss 12:9                                 root stylesheet
 @ ./_path_/application.scss

The following seems to fix the issue in webpack/sass-loader:

-@import "node_modules/bootstrap/scss/functions";
-@import "node_modules/bootstrap/scss/variables";
-@import "node_modules/bootstrap/scss/mixins";
+@import "bootstrap/scss/functions";
+@import "bootstrap/scss/variables";
+@import "bootstrap/scss/mixins";

https://github.com/apalfrey/select2-bootstrap-5-theme/blob/ab448b2ac36a6f7f90b162e384ca2b1469a3cc1f/src/select2-bootstrap-5-theme.scss#L5-L7

taketo1113 commented 2 weeks ago

It have workaround to use legacy api of sass-loader option.

If use legacy api of sass-loader, add following settings in webpack config.

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              api: "legacy",
              // Your options
            },
          },
        ],
      },
    ],
  },
};