chushihua
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8"
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# px2rem-loader
|
||||
|
||||
a [webpack](http://webpack.github.io/) loader for [px2rem](https://github.com/songsiqi/px2rem)
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/px2rem-loader.svg
|
||||
[npm-url]: https://npmjs.org/package/px2rem-loader
|
||||
[travis-image]: https://img.shields.io/travis/Jinjiang/px2rem-loader.svg
|
||||
[travis-url]: https://travis-ci.org/Jinjiang/px2rem-loader
|
||||
[downloads-image]: http://img.shields.io/npm/dm/px2rem-loader.svg
|
||||
[downloads-url]: https://npmjs.org/package/px2rem-loader
|
||||
|
||||
## Install
|
||||
|
||||
`npm install px2rem-loader`
|
||||
|
||||
## webpack config
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// ...
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.css$/,
|
||||
use: [{
|
||||
loader: 'style-loader'
|
||||
}, {
|
||||
loader: 'css-loader'
|
||||
}, {
|
||||
loader: 'px2rem-loader',
|
||||
// options here
|
||||
options: {
|
||||
remUni: 75,
|
||||
remPrecision: 8
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Please see [px2rem](https://github.com/songsiqi/px2rem) for more information about query parameters of px2rem.
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('./lib/px2rem-loader')
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
var loaderUtils = require('loader-utils')
|
||||
var Px2rem = require('px2rem')
|
||||
|
||||
module.exports = function (source) {
|
||||
var options = loaderUtils.getOptions(this)
|
||||
var px2remIns = new Px2rem(options)
|
||||
return px2remIns.generateRem(source)
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "px2rem-loader",
|
||||
"version": "0.1.9",
|
||||
"description": "css post loader for px2rem",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha test.js --slow 2000"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Jinjiang/px2rem-loader.git"
|
||||
},
|
||||
"keywords": [
|
||||
"webpack",
|
||||
"loader"
|
||||
],
|
||||
"author": "Jinjiang",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Jinjiang/px2rem-loader/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Jinjiang/px2rem-loader",
|
||||
"dependencies": {
|
||||
"loader-utils": "^1.1.0",
|
||||
"px2rem": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "~3.0.0",
|
||||
"mocha": "~2.2.5"
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
var expect = require('chai').expect
|
||||
var loader = require('./lib/px2rem-loader')
|
||||
|
||||
describe('Loader', function () {
|
||||
|
||||
it('should transform px value into rem', function () {
|
||||
var output = loader.call({}, 'body {width: 750px}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 10rem;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Transform Value Comment', function () {
|
||||
|
||||
it('should support `no` transform value comment', function () {
|
||||
var output = loader.call({}, 'body {width: 750px; /*no*/}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 750px;\n}')
|
||||
})
|
||||
|
||||
it('should support `px` transform value comment', function () {
|
||||
var output = loader.call({}, 'body {width: 750px; /*px*/}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('[data-dpr="1"] body {\n width: 375px;\n}\n\n[data-dpr="2"] body {\n width: 750px;\n}\n\n[data-dpr="3"] body {\n width: 1125px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Transform Media Query & Key Frames', function () {
|
||||
|
||||
it('should support @media', function () {
|
||||
var output = loader.call({}, '@media only screen and (min-device-width: 360px) {body {width: 750px; height: 200px; /*px*/ border-width: 1px; /*no*/}}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('@media only screen and (min-device-width: 360px) {\n body {\n width: 10rem;\n border-width: 1px;\n }\n\n [data-dpr="1"] body {\n height: 100px;\n }\n\n [data-dpr="2"] body {\n height: 200px;\n }\n\n [data-dpr="3"] body {\n height: 300px;\n }\n}')
|
||||
})
|
||||
|
||||
it('should support @keyframes', function () {
|
||||
var output = loader.call({}, '@keyframes anim {0% {transform: none; height: 75px; border-width: 1px; /*no*/} 100% {transform: none; height: 150px; border-width: 2px; /*no*/}}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('@keyframes anim {\n 0% {\n transform: none;\n height: 1rem;\n border-width: 1px;\n }\n\n 100% {\n transform: none;\n height: 2rem;\n border-width: 2px;\n }\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Loader Query', function () {
|
||||
|
||||
it('should support `remUnit` query', function () {
|
||||
var output = loader.call({query: '?remUnit=64'}, 'body {width: 640px}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 10rem;\n}')
|
||||
})
|
||||
|
||||
it('should support `remUnit` query', function () {
|
||||
var output = loader.call({query: '?remUnit=112.5'}, 'body {width: 640px}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 5.688889rem;\n}')
|
||||
})
|
||||
|
||||
it('should support `remPrecision` query', function () {
|
||||
var output = loader.call({query: '?remPrecision=3'}, 'body {width: 1000px}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 13.333rem;\n}')
|
||||
})
|
||||
|
||||
it('should support `remUnit` & `remPrecision` query', function () {
|
||||
var output = loader.call({query: '?remUnit=112.5&remPrecision=3'}, 'body {width: 640px}')
|
||||
expect(output).is.a('string')
|
||||
expect(output).to.equal('body {\n width: 5.689rem;\n}')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user