zoukankan      html  css  js  c++  java
  • [AngularJS + Webpack] Requiring CSS & Preprocessors

    Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By adding a single line to your Webpack config, you can require you CSS, Stylus, Less, etc. files right from your directives and keep everything together.

    Install:

    npm install -D style-loader css-loader stylus-loader

    webpack.config.js:

    'style!css' means compile css first then style. The webpack read from right to left.

    So 'style!css!stylus': compile stylus, then css, final style.

    module.exports = {
        entry: {
            app: ['./app/index.js']
        },
        output: {
            path: './build',
            filename: 'bundle.js'
        },
        module: {
            loaders: [
                {test: /.js$/, loader: 'babel-loader', exclude: /node_modules/},
                {test: /.html$/, loader: 'html-loader', exclude: /node_modules/},
                {test: /.css$/, loader: 'style!css', exclude: /node_modules/},
                {test: /.css$/, loader: 'style!css!stylus', exclude: /node_modules/}
            ]
        }
    };
    export default (ngModule) => {
        ngModule.directive('hello',  () => {
            require('./hello.css');
            return {
                restrict: 'E',
                scope: {},
                template: require('./hello.html'),
                controllerAs: 'vm',
                controller: function() {
                    var vm = this;
                    vm.greeting = "Hello";
                }
            }
        })
    
    }
  • 相关阅读:
    Leetcode题解(十六)
    Leetcode题解(十五)
    Leetcode题解(十四)
    Leetcode题解(十三)
    Leetcode题解(十二)
    Leetcode题解(十一)
    php数据库访问及增删改
    克隆对象及加载类
    抽象
    PHP继承
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4792735.html
Copyright © 2011-2022 走看看