# px2rem-webpack-plugin-webpack3

> make page to auto-fit responsive screen

Latest version **1.0.0** (published 2017-07-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install px2rem-webpack-plugin-webpack3
pnpm add px2rem-webpack-plugin-webpack3
yarn add px2rem-webpack-plugin-webpack3
bun add px2rem-webpack-plugin-webpack3
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-07-26 |
| First published | 2017-07-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | johnsonliang1988 |

## Links

- npm: https://www.npmjs.com/package/px2rem-webpack-plugin-webpack3
- npm.io page: https://npm.io/package/px2rem-webpack-plugin-webpack3

## Dependencies (2)

- [css](https://npm.io/package/css.md) ^2.2.1
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.6.1

## Recent versions

- 1.0.0 (latest) — 2017-07-26

## README

[ ![Codeship Status for xinchaobeta/px2rem-webpack-plugin](https://codeship.com/projects/97fa7040-00c2-0134-74ce-4a275b923e46/status?branch=master)](https://codeship.com/projects/153298)

## Installation

``` bash
npm install px2rem-webpack-plugin --save-dev
```

## Usage

The plugin should be used with [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin)
``` javascript
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Px2remWebpackPlugin = require('px2rem-webpack-plugin');

var webpackConfig = {
  entry: 'app.js',
  output: {
    path: 'dist',
    filename: '[hash].app.js'
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new Px2remWebpackPlugin({originScreenWidth: 750}),
  ]
};
```

This will generate a file dist/index.html containing the following:

``` html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>

  <script>
  document.documentElement.style.fontSize = 100 * innerWidth / 320 + 'px'
  addEventListener('load', function() {
    setTimeout(function(){
       document.documentElement.style.fontSize = 100 * innerWidth / 320 + 'px'
       window.unit = 100 * innerWidth / 320;
       var e = document.createEvent('Event');
       e.initEvent('adjustReady', true, true);
       window.dispatchEvent(e);
    }, 480);
  })
  addEventListener('orientationchange', function() {
      setTimeout(function(){
        document.documentElement.style.fontSize = 100 * innerWidth / 320 + 'px'
      }, 480)

  });
  </script>
</head>
  <body>
  <script src="6062412d2f3140cc3dd0.app.js"></script></body>
</html>
```

And translate the `px` to `rem` in all css files, before webpack [css-loader](https://github.com/webpack/css-loader) handle the css source.
> The plugin can also be used together with [sass-loader](https://github.com/jtangelder/sass-loader), [less-loader](https://github.com/webpack/less-loader) or [stylus-loader](https://github.com/shama/stylus-loader).
<br>It will auto handle properly after `sass/less/stylus` compilation but before the `css-loader`

> Note: css files in `node_modules` will not be translated.

**For example** the css below

``` css
.abc { width: 750px; }
```
will be automatically compiled to
``` css
.abc { width: 3.2rem; }
```



## Contribution Guide

``` bash
# dev plugin
make dev  ## in one bash
make debug ## in another bash

# build for publish
make build

# run tests
make test
```

---
_Source: https://npm.io/package/px2rem-webpack-plugin-webpack3 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
