A toolchain for developing universal (Node.js and browser) JavaScript packages.
npm i create-universal-package --save-dev
Usage: cup [options] [command]
Commands:
build, b Build your package
build-tests Build your tests
clean, c Clean build artifacts
help Display help
Options:
-h, --help Output usage information
-v, --version Output the version number
Any .js
files at the root of any __tests__
directory will be added to the test bundle. For browser-only test files, you can use a .browser.js
extension. This also works for node-only tests and .node.js
.
Aliases for either true
or false
depending on the build target. Use this in conjunction with conditionals to check for environment, and dead code will automatically be eliminated appropriately.
For linting purposes, __BROWSER__
and/or __NODE__
conditional checks establish appropriate environment globals. For example:
process.title; // fails `cup/no-undef`
window.location; // fails `cup/no-undef`
// passes lint
if (__BROWSER__) {
document.body.appendChild(document.createTextNode('hello world'));
}
// passes lint
if (__NODE__) {
process.stdout.write('hello world');
}
// passes lint
const topLevel = __BROWSER__ ? window : global;
By default, only universal globals (e.g. setTimeout
and console
) are set everywhere.
Alias for process.env.NODE_ENV !== 'production'
. By convention, it is assumed that module consumers are statically inlining the value of process.env.NODE_ENV
in browser bundles.
create-universal-package prunes unused imports in scenarios like the following:
import doNodeThing from 'some-package';
export function foo() {
console.log('foo');
if (__NODE__) {
doNodeThing();
}
}
import doNodeThing from 'some-package';
export function foo() {
console.log('foo');
doNodeThing();
}
export function foo() {
console.log('foo');
}
Notice how the some-package
import gets eliminated from the browser result. This is what we want, but keep in mind any dependencies that perform side effects when imported could be eliminated.
create-universal-package's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.