Sha256: 747dde5613dc87ac4ebec6cb1ba44f13bd0a20307f93f071c21d3c925d8cea31

Contents?: true

Size: 1.22 KB

Versions: 27

Compression:

Stored size: 1.22 KB

Contents

const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { resolve } = require('path')
const devServer = require('../dev_server')
const config = require('../config')

const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
const isHMR = inDevServer && (devServer && devServer.hmr)

const styleLoader = {
  loader: 'style-loader',
  options: {
    hmr: isHMR,
    sourceMap: true
  }
}

const getStyleRule = (test, modules = false, preprocessors = []) => {
  const use = [
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
        importLoaders: 2,
        localIdentName: '[name]__[local]___[hash:base64:5]',
        modules
      }
    },
    {
      loader: 'postcss-loader',
      options: {
        config: { path: resolve() },
        sourceMap: true
      }
    },
    ...preprocessors
  ]

  const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }

  if (config.extract_css) {
    use.unshift(MiniCssExtractPlugin.loader)
  } else {
    use.unshift(styleLoader)
  }

  // sideEffects - See https://github.com/webpack/webpack/issues/6571
  return Object.assign({}, { test, use, sideEffects: !modules }, options)
}

module.exports = getStyleRule

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/utils/get_style_rule.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/utils/get_style_rule.js
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/utils/get_style_rule.js
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/utils/get_style_rule.js
jester-data-8.0.0 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-5.2.1 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-2.0.1 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-1.1.0 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-1.0.0 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-0.0.0.1.0 node_modules/@rails/webpacker/package/utils/get_style_rule.js
ezii-os-0.0.0.0.1 node_modules/@rails/webpacker/package/utils/get_style_rule.js
webpacker-4.0.7 package/utils/get_style_rule.js
webpacker-4.0.6 package/utils/get_style_rule.js
webpacker-4.0.5 package/utils/get_style_rule.js
webpacker-4.0.4 package/utils/get_style_rule.js
webpacker-4.0.3 package/utils/get_style_rule.js
webpacker-4.0.2 package/utils/get_style_rule.js
webpacker-4.0.1 package/utils/get_style_rule.js
webpacker-4.0.0 package/utils/get_style_rule.js
webpacker-4.0.0.rc.8 package/utils/get_style_rule.js