Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

An order of required styles is wrong. #165

Closed
mtnt opened this issue Mar 17, 2016 · 3 comments
Closed

An order of required styles is wrong. #165

mtnt opened this issue Mar 17, 2016 · 3 comments

Comments

@mtnt
Copy link

mtnt commented Mar 17, 2016

Hi guys. I have some problem and I really can`f find a way...

I trying to make separate style files for different mobile devices form-factors.

Files structure:

A UIKit layer:

// ./base/kit/mobile.kit.styl
@import '../variables/variables.styl';

.mobile {
    color: $red;
}
// ./base/kit/tablet.kit.styl
.tablet {
    color: $blue;
}

Base layer:

// ./base/base/mobile.base.styl
@import '../kit/mobile.kit.styl';

body.mobile {
    height: 100%;
    color: #fff;
}
// ./base/base/tablet.base.styl
@import './mobile.base.styl'; //with mobile.kit included
@import '../kit/tablet.kit.styl'; // overriding some mobile.kit classes

body.tablet {
    height: 90%;
    color: #fff;
}

Entry points:

// ./base/entry/mobile.entry.js
require('../base/mobile.base.styl');
require('../base/base.js');
// ./base/entry/tablet.entry.js
require('../base/tablet.base.styl');
require('../base/base.js');

Base.js:

// some code without includes

Webpack config:

var ExtractTextPlugin = require('extract-text-webpack-plugin');

//var autoprefixer = require('autoprefixer');
//var precss       = require('precss');

module.exports = {
    context: __dirname + '/static',
    entry:   {
        mobile: './base/entry/mobile.entry.js',
        tablet: './base/entry/tablet.entry.js'
    },
    output:  {
        path:       __dirname + '/assets/js',
        filename:   '[name].base.js'
    },
    module:  {
        loaders: [
            {
                test:   /\.styl$/,
                loader: ExtractTextPlugin.extract('css!stylus')
            }
        ]
    }
    ,

    plugins: [
        new ExtractTextPlugin('../css/[name].base.css')
    ]

Result of packing:

// mobile.base.css
.mobile {
  color: #f00;
}
body.mobile {
  height: 100%;
  color: #fff;
}
// tablet.base.css
.mobile {
  color: #f00;
}
body.mobile {
  height: 100%;
  color: #fff;
}
.tablet {
  color: #00f;
}
body.tablet {
  height: 90%;
  color: #fff;
}

All is good: tablet styles are after mobile - what I need... Was.. Unless I added require into the base.js

// ./base/base/base.js
// < some code

require('../../layout/page.index/page.index.js');
// ./layout/page.index/page.index.js
require('./page.index.styl');

Result:

// mobile.base.css
.mobile {
  color: #f00;
}
body.mobile {
  height: 100%;
  color: #fff;
}
.page {
  font-size: 3px;
}
// tablet.base.css
.page { //<< WHY IS IT HERE?
  font-size: 3px;
}
.mobile {
  color: #f00;
}
body.mobile {
  height: 100%;
  color: #fff;
}
.tablet {
  color: #00f;
}
body.tablet {
  height: 90%;
  color: #fff;
}
// << WHY NOT HERE?
@mtnt
Copy link
Author

mtnt commented Mar 17, 2016

I have made an experiment and used another one layer - desktop.
At that case right position was on desktop only. I guess it is because of the desktop was handled first (alphabetically), same as the "mobile" was before "tablet".

@jhnns
Copy link
Member

jhnns commented Oct 3, 2016

Is this a duplicate of #200?

@bebraw
Copy link
Contributor

bebraw commented Jan 28, 2017

Yup. Let's close in favor of #200. Better continue there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants