Skip to content

Commit

Permalink
@wq/rollup-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Oct 23, 2020
1 parent 429f34e commit 45a5b5b
Show file tree
Hide file tree
Showing 14 changed files with 7,585 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,7 +2,10 @@
*.egg-info
*.egg
*.sw?
*.tgz
build
dist
README.rst
wq/
.eggs
node_modules
11 changes: 9 additions & 2 deletions .travis.yml
Expand Up @@ -20,7 +20,7 @@ addons:
- gdal-bin
matrix:
include:
- name: "Defaults (Python 3.8, SpatialLite, No NPM)"
- name: "wq start (Python 3.8, SpatialLite, No NPM)"
- name: "Python 3.7"
python: 3.7
- name: "Python 3.6"
Expand All @@ -36,7 +36,14 @@ matrix:
- name: "NPM"
env:
- WITH_NPM=1
- name: "Lint"
- name: "@wq/rollup-plugin"
install:
- cd packages/rollup-plugin
- npm ci
script:
- npm test
- npm run lint
- name: "Python Lint"
env:
- LINT=1
install:
Expand Down
25 changes: 25 additions & 0 deletions packages/rollup-plugin/.eslintrc.js
@@ -0,0 +1,25 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:jest/recommended'
],
globals: {
module: 'readonly',
process: 'readonly',
__dirname: 'readonly'
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 12,
sourceType: 'module'
},
plugins: ['react'],
rules: {}
};
2 changes: 2 additions & 0 deletions packages/rollup-plugin/.npmignore
@@ -0,0 +1,2 @@
__tests__
*.tgz
64 changes: 64 additions & 0 deletions packages/rollup-plugin/README.md
@@ -0,0 +1,64 @@
# @wq/rollup-plugin

@wq/rollup-plugin makes it possible to create custom plugins that integrate with [wq.app](https://wq.io/wq.app)'s pre-built **wq.js** bundle. @wq/rollup-plugin remaps certain module imports to leverage exports from the bundle.

> Note: While @wq/rollup-plugin can used in a project build, it is primarily intended for use by authors of plugins distributed as reusable Django apps. Django projects created with `wq start --with-npm` (& Create React App) use CRA's Webpack configuration by default instead of Rollup. (See [@wq/cra-template](https://github.com/wq/wq.start/tree/master/packages/cra-template))
### Usage

```bash
npm i @wq/rollup-plugin
```

```javascript
// rollup.config.js
import wq from '@wq/rollup-plugin';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';

export default [
{
input: 'src/input.js',
plugins: [
wq(),
babel({
presets: ['@babel/preset-react'],
babelHelpers: 'inline'
})
resolve(),
commonjs(),
replace({
'process.env.NODE_ENV': '"production"',
delimiters: ['', '']
})
],
treeshake: {
propertyReadSideEffects: false
},
output: {
file: 'static/app/js/pluginName.js',
sourcemap: true,
format: 'esm'
}
}
];
```

With the above configuration, the output bundle will include the source of any third-party `node_modules/`, _except_ those known to already be included in **wq.js**. Those imports will be changed to a relative import to `./wq.js` (which is typically deployed to the `static/js/app` folder in a Django project).

In addition to keeping bundle sizes small, @wq/rollup-plugin helps ensure that there is only one copy of key libraries like React. Below is the full list of modules currently exported by **wq.js** for consumption via this plugin:

- `react`
- `react-dom`
- `prop-types`
- `@material-ui/utils`
- `@material-ui/styles`
- `@material-ui/core/styles/withStyles`
- `@material-ui/core/styles/colorManipulator`
- `mapbox-gl`
- `@wq/react`
- `@wq/material`
- `@wq/map`
- `@wq/mapbox`

0 comments on commit 45a5b5b

Please sign in to comment.