Repository: Jinjiang/px2rem-loader Branch: master Commit: d1a85cc45aab Files: 14 Total size: 7.4 KB Directory structure: gitextract_717fc_tc/ ├── .gitignore ├── .travis.yml ├── README.md ├── examples/ │ ├── .gitignore │ ├── README.md │ ├── foo.css │ ├── index.html │ ├── main.js │ ├── package.json │ └── webpack.config.js ├── index.js ├── lib/ │ └── px2rem-loader.js ├── package.json └── test.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Logs logs *.log npm-debug.log* # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory node_modules # Optional npm cache directory .npm # Optional REPL history .node_repl_history # Others .DS_Store ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "8" ================================================ FILE: README.md ================================================ # 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: { remUnit: 75, remPrecision: 8 } }] }] } } ``` Please see [px2rem](https://github.com/songsiqi/px2rem) for more information about query parameters of px2rem. ## Example See an example [here](./examples). ================================================ FILE: examples/.gitignore ================================================ node_modules dist ================================================ FILE: examples/README.md ================================================ # px2rem-examples Based on webpack v4. ## How to start ``` bash npm install npm run build open index.html ``` ## Things should note * `webpack.config.js`: the way to config px2rem-loader and other webpack config. * `foo.css`: the way to use REM unit in CSS source file. * `index.html`: the way to include `lib.flexible`. ================================================ FILE: examples/foo.css ================================================ h1 { width: 480px; /*px*/ padding: 0.5em 1em; font-size: 64px; border: 1px solid #333; /*no*/ background: #eeeeee; } ================================================ FILE: examples/index.html ================================================ px2rem-loader example

Hello World

================================================ FILE: examples/main.js ================================================ import './foo.css' ================================================ FILE: examples/package.json ================================================ { "name": "px2rem-examples", "version": "1.0.0", "private": true, "scripts": { "dev": "webpack --watch", "build": "webpack", "test": "echo \"Error: no test specified\" && exit 1" }, "license": "ISC", "devDependencies": { "css-loader": "^2.1.0", "px2rem-loader": "^0.1.9", "style-loader": "^0.23.1", "webpack": "^4.28.1", "webpack-cli": "^3.2.1" } } ================================================ FILE: examples/webpack.config.js ================================================ module.exports = { mode: 'development', entry: './main.js', output: { filename: 'example.js' }, module: { rules: [{ test: /\.css$/, use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'px2rem-loader', // // options here // options: { // remUnit: 75, // remPrecision: 8 // } }] }] } } ================================================ FILE: index.js ================================================ module.exports = require('./lib/px2rem-loader') ================================================ FILE: lib/px2rem-loader.js ================================================ 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) } ================================================ FILE: package.json ================================================ { "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" } } ================================================ FILE: test.js ================================================ 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}') }) })