美文网首页我爱编程
使用less写微信小程序样式

使用less写微信小程序样式

作者: a年少有为 | 来源:发表于2018-04-13 10:53 被阅读45次

新建文件目录

src: 源代码

dist: gulp解析后的代码

package.json: 需要的模块,内容如下

{

  "homepage": "https://github.com/nimojs/gulp-book",

  "version": "0.0.1",

  "description": "",

  "main": "gulpfile.js",

  "license": "MIT",

  "devDependencies": {

    "gulp": "^3.9.1",

    "gulp-autoprefixer": "^4.0.0",

    "gulp-cssnano": "^2.1.2",

    "gulp-less": "^3.0.2",

    "gulp-rename": "^1.2.2"

  }

}

gulpfile.js: gulp配置文件

//gulpfile.js

const gulp = require('gulp');

const less = require('gulp-less');

const cssnano = require('gulp-cssnano');

const rename = require('gulp-rename');

const autoprefixer = require('gulp-autoprefixer');

gulp.task('less', function () {

    gulp.src('./src/**/*.less')

        .pipe(less())

        // .pipe(cssnano())

        .pipe(rename(function(path){

            path.extname = '.wxss';

        }))

        .pipe(gulp.dest('./dist'))

});

gulp.task('pages', function() {

    return gulp.src([

        '!src/**/*.less',

        'src/**'

        ]).pipe(gulp.dest('./dist'))

})

gulp.task('auto', function () {

    gulp.watch(['src/**/*.less'], ['less']);

    gulp.watch([

        '!src/**/*.less',

        'src/**'

        ], ['pages']);

})

// 使用 gulp.task('default') 定义默认任务

// 在命令行使用 gulp 启动 less 任务和 auto 任务

// gulp.task('default', ['less', 'pages', 'auto'])

gulp.task('default', ['less', 'pages', 'auto']);

运行gulp命令

相关文章

  • 【总结】2017.01.12

    2017.01.12 - 计划 小程序-微信聊天 - 实际完成 安装webStorm,用less写样式转换成小程序...

  • 使用less写微信小程序样式

    新建文件目录 src: 源代码 dist: gulp解析后的代码 package.json: 需要的模块,内容如下...

  • 在微信小程序中使用less/sass

    微信小程序中的样式文件wxss等同于css,并不支持less或sass语法。 插件使用演示如下: Easy Les...

  • Vscode 配置less转wxss

    在开发微信小程序时,写css会比较麻烦,效率不高,最好的办法就是使用less或者sass,可以使用gulp等配置编...

  • 微信小程序使用 Less

    PS:设置前请确保电脑已经安装 webstorm、node、npm和less。 活不多说,直接上图 1、设置 >...

  • WebStorm小程序开发,格式化样式文件时rpx前被添加空格的

    问题: 使用WebStorm开发微信小程序,格式化样式文件时,带rpx的值格式化时总被空格分开,导致小程序样式错误...

  • 原生微信小程序使用less

    用惯了预处理的我实在受不了用原生CSS写样式这种令人崩溃的开发体验,然后想在项目中使用less。 1.Ctrl+S...

  • 微信小程序基础

    微信小程序介绍微信小程序开发工具的使用微信小程序框架文件微信小程序逻辑层微信小程序视图层微信小程序组件介绍微信小程...

  • 【微信小程序】使用微信原生样式

    1. 微信小程序 一个小程序页面包含四个文件: 文件类型必须作用相当于web中的wxml是页面结构htmlwxss...

  • 2020-05-14

    微信小程序开发使用计算样式calc的坑 (calc设置无效)wxss样式中如果要使用calc计算宽度或高度需要注意...

网友评论

    本文标题:使用less写微信小程序样式

    本文链接:https://www.haomeiwen.com/subject/tyyxgxtx.html