Skip to content

Support javascript in the .bootstraprc config file #125

@brunohcastro

Description

@brunohcastro

While trying to use Root Urls and still get my assets through the url/file-loader (for things like $fa-font-path overrides), I had some problems to set the url-loader?root query to the correct folder. So I managed to do so by tweaking the utils/parseConfig.js from:

export default function(configPath) {
  const configContent = stripComments(fs.readFileSync(configPath, 'utf8'));
  return yaml.safeLoad(configContent);
 }

To:

export default function(configPath) {  
  try {
    const configContent = JSON.stringify(require(configPath));
  } catch (e) {
    const configContent = stripComments(fs.readFileSync(configPath, 'utf8'));
  }

   return yaml.safeLoad(configContent);
 }

After that, I created a .bootstraprc with something like:

#!/usr/bin/env node

var path = require('path');

module.exports = {
    bootstrapVersion: 4,
    useFlexbox: true,
    styleLoaders: [
        'style',
        'css?root=' + path.join(__dirname, 'src') + '&importLoaders=1',
        'postcss',
        'resolve-url',
        'sass?sourceMap'
    ],
    extractStyles: false,
    preBootstrapCustomizations: path.join(__dirname, 'src', 'scss', '_variables.scss'),
    appStyles: path.join(__dirname, 'src', 'scss', 'application.scss'),
    styles: {
        'mixins': true,
        'normalize': true
    },
    scripts: {
        'alert': true,
        'button': true
    }
}

So it all just worked!

I think this is a very good tweak, it is so much more flexible now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions