Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Aug 19, 2019
0 parents commit 78c687b
Show file tree
Hide file tree
Showing 19 changed files with 6,966 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true,
"node": true,
},
"parserOptions": {
"sourceType": "module",
},
"plugins": [
"react"
],
"extends": [
"eslint:recommended", "google"
],
"rules": {
"no-console": 0,
"require-jsdoc": 0,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# OS or Editor folders
.DS_Store

# Node stuff
node_modules

# Build files
public
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Rollup Native Modules Boilerplate

A demo app showcasing the use of real JavaScript modules in production—complete with cross-browser fallbacks for legacy browsers.

The techniques used in this demo are described in the article [Using Native JavaScript Modules in Production Today](https://philipwalton.com/articles/using-native-javascript-modules-in-production-today/).

🚀  **[View the demo on Glitch](https://rollup-native-modules-boilerplate.glitch.me/)**  👉

## Features

To show that this technique can work for most types of applications, this demo is a React app and includes advanced features like:

* Babel transforms (including JSX)
* CommonJS dependencies (e.g. `react`, `react-dom`)
* CSS dependencies
* Asset hashing
* Code splitting
* Dynamic import (w/ polyfill fallback)
* module/nomodule fallback

To see how all these features are configured, view the Rollup config file ([`rollup.config.js`](/rollup.config.js)). To see the generated output, view the `public` directory after building the app (see below).

## Building and running the app locally

To run the app locally, [clone](https://help.github.com/en/articles/cloning-a-repository) this repo and `npm install` all dependencies, then run the following command:

```sh
npm start
```

This will start a local server at `http://localhost:8080`, where you can view the app.

If you want to run the app _and_ have Rollup monitor the code for changes (and rebundle), you can run:

```sh
npm run watch
```

To build the app without starting the development server, run:

```sh
npm run build
```

### `development` vs `production` mode

By default the app is started in development mode, which means the bundle output is unminified, and a `nomodule` bundle is not generated. You can change this by prefixing any of the above commands with `NODE_ENV=production`, for example:

```sh
NODE_ENV=production npm start
```



43 changes: 43 additions & 0 deletions clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2019 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const pkg = require('./package.json');


async function main() {
const manifestPath = path.join(pkg.config.publicDir, 'manifest.json');
const manifest = fs.existsSync(manifestPath) ?
await fs.readJson(manifestPath) : {};

const publicModules = new Set(
await globby('*.+(js|mjs)', {cwd: pkg.config.publicDir}));

// Remove files from the `publicModules` set if they're in the manifest.
for (const fileName of Object.values(manifest)) {
if (publicModules.has(fileName)) {
publicModules.delete(fileName);
}
}

// Delete all remaining modules (not in the manifest).
for (const fileName of publicModules) {
await fs.remove(path.join(pkg.config.publicDir, fileName));
}
}

main();
Loading

0 comments on commit 78c687b

Please sign in to comment.