Skip to content

Bourbon Sass Mixin Library with vue-loader #95

@tikiatua

Description

@tikiatua

Hi there,
Thank you for the amazing vue-loader. I have been looking for something similar for quite some time and really love the approach of keeping style, template and javascript of a component in a single file.

Is it at all possible to use the bourbon sass mixin library with the vue-loader? I did include it in the webpack setup in different ways but have not been able to use bourbon functions in my styles (i.e. the very handy tint-function).

Any help would be greatly appreciated.

var path = require('path');
var webpack = require('webpack');

var node_modules = path.resolve(__dirname, 'node_modules');
var pathToBourbon = require('node-bourbon').includePaths;

module.exports = {
    entry: {
        public: [path.resolve(__dirname, 'app/public/main.js')],
    },
    output: {
        path: path.resolve(__dirname, 'build/assets'),
        filename: '[name].bundle.js',
        publicPath: '/assets/'
    },
    module: {
        loaders: [
            {
                // parse vue components
                test: /\.vue$/,
                loader: 'vue',
                exclude: node_modules
            }, {
                // edit this for additional asset file types
                test: /\.(png|jpg|gif)$/,
                loader: 'file?name=[name].[ext]?[hash]',
                exclude: node_modules
            }, {
                // parse css styles
                test: /\.css$/,
                loader: 'style!css',
                exclude: node_modules
            }, {
                // parse scss styles
                test: /\.scss$/,
                loader: 'style!css!sass?includePaths[]=' + pathToBourbon
            }, {
                // parse javascript styles
                test: /\.js$/,
                loader: 'babel',
                exclude: node_modules
            }
        ],
    },
    vue: {
        loaders: {
            // scss loader-statement is required to make scss syntax work
            // however, includePaths do not seem to import the tint-function or any mixins
            scss: 'style!css!sass?includePaths[]=' + pathToBourbon
        }
    },
    sassLoader: {
        includePaths: [pathToBourbon]
    },
    babel: {
        presets: ['es2015', 'stage-0'],
        plugins: ['transform-runtime']
    }
};

if (process.env.NODE_ENV === 'production') {
  module.exports.plugins = [
    new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: '"production"'
        }
    }),
    new webpack.optimize.UglifyJsPlugin({
        compress: {
            warnings: false
        }
    }),
    new webpack.optimize.OccurenceOrderPlugin()
    ]
} else {
    module.exports.devtool = '#source-map'
}

Example component

<style lang="scss">
$custom-red: red;
.header {
    color: $custom-red;
    border: 1px solid tint($custom-red, 20%);
}
</style>

<template>
    <div class="header">
        <h1>Custom header content</h1>
    </div>
</template>

<script>
    module.exports = {}
</script>
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions