Giter VIP home page Giter VIP logo

rollup-starter-lib's Introduction

rollup-starter-lib

Greenkeeper badge

This repo contains a bare-bones example of how to create a library using Rollup, including importing a module from node_modules and converting it from CommonJS.

We're creating a library called how-long-till-lunch, which usefully tells us how long we have to wait until lunch, using the ms package:

console.log('it will be lunchtime in ' + howLongTillLunch());

Getting started

Clone this repository and install its dependencies:

git clone https://github.com/rollup/rollup-starter-lib
cd rollup-starter-lib
npm install

npm run build builds the library to dist, generating three files:

  • dist/how-long-till-lunch.cjs.js A CommonJS bundle, suitable for use in Node.js, that requires the external dependency. This corresponds to the "main" field in package.json
  • dist/how-long-till-lunch.esm.js an ES module bundle, suitable for use in other people's libraries and applications, that imports the external dependency. This corresponds to the "module" field in package.json
  • dist/how-long-till-lunch.umd.js a UMD build, suitable for use in any environment (including the browser, as a <script> tag), that includes the external dependency. This corresponds to the "browser" field in package.json

npm run dev builds the library, then keeps rebuilding it whenever the source files change using rollup-watch.

npm test builds the library, then tests it.

Variations

  • babel — illustrates writing the source code in ES2015 and transpiling it for older environments with Babel
  • buble — similar, but using Bublé which is a faster alternative with less configuration
  • TypeScript — uses TypeScript for type-safe code and transpiling

License

MIT.

rollup-starter-lib's People

Contributors

eventualbuddha avatar greenkeeper[bot] avatar julkue avatar mikeharder avatar qm3ster avatar reed-jones avatar rich-harris avatar rickhanlonii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rollup-starter-lib's Issues

Bug: Wrong use of the package.json `browser` field

I notice in this example that it is referencing the umd build in the dist folder in the browser field of package.json:

{
  "main": "dist/how-long-till-lunch.cjs.js",
  "module": "dist/how-long-till-lunch.esm.js",
  "browser": "dist/how-long-till-lunch.umd.js",
}

Thinking of interop with other tools, I wonder whether this is right?

I think Browserify and Webpack both use the browser field as having the meaning 'the entry point for this package, for browsers'. But they assume 'normal' cjs code.

For example have a look at the browser field in the package.json of debug:

{
  "main": "./src/index.js",
  "browser": "./src/browser.js",
  "unpkg": "./dist/debug.js"
}

Notice how they use a file in the src folder here. Both Browserify and Webpack will pick up this file and package / bundle it, wrapping it with a umd wrapper for umd builds.

So I wonder, is it right that the file this project is setting for the browser field is a umd build, that already has a umd wrapper? Won't this file end up being wrapped twice?

Babel variant out of date

the babel variant still uses a number of properties that have been renamed like entry instead of input.

Also this could be of importance: regarding the transform-runtime plugin vs external-helpers plugins for babel.

Set as template in Github

Would it be possible to make this a Github template as well within the repos settings?
It'd make it handy to create a new repo directly from this in Github vs cloning each time.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

How to use with Jasmine

I am trying to figure if I can use rollup to resolve modules for jasmine.

With Babel I can use babel-node and run Jasmine using API like:
https://gist.github.com/mauvm/172878a9646095d03fd7

I would like to avoid pulling in Babel for a project that targets modern node.
Should I try to use buble? but I only need ESM-> CJS

Edit.
Basically, I am looking for "roll as you go" option :)

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

How to use with uglify or other minifier?

Hey,
this is a fantastic starter kit for building a lib.

What if I want to serve the cjs, umd, and esm version both unminified and minified? For example:

  • mylib.cjs.js
  • mylib.cjs.min.js
  • mylib.esm.js
  • mylib.esm.min.js
  • mylib.umd.js
  • mylib.umd.min.js

How do I obtain this?

Thanks

How to build for <script type="module">

Hi, if your library depends on an external package, how can you build for <script type="module">? Bonus points if you can make it work as CJS, too.

Here's our library

// my-library.js
import fetch from 'isomorphic-unfetch'
export default function (url) {
  // do stuff
  return fetch(url)
}

Using rollup es format, can this work?

<script type="module">
  import myLibrary from './dist/my-library.es.js'
  myLibrary(42)
</script>

Right now you it warns you

Uncaught TypeError: Failed to resolve module specifier "isomorphic-unfetch". Relative references must start with either "/", "./", or "../".`

If you change the library's import to something like ./node_modules/isomorphic-unfetch/es-version.js it'll work locally but of course break the built version. What to do? What is this rabbit hole?

Any help would be great appreciated! Thank you.

Possibly related

Question: why don't we set the target environment settings for `babel-preset-env` part?

I'm talking about babel branch specifically.

Correct me if I'm wrong, but the point of babel-preset-env is to automate the Babel settings, specifying only the target platform, like "targets": { "browsers": ["last 2 versions", "ie >= 7"] } or "browsers": "> 5%" and so on. The Babel then knows what level of transpiling is needed. Because maybe, for example, your internal corporate portal is ran by Chrome users only. Or, for example, you can't sort out IE flexbox bugs and block it completely.

For example, .babelrc would have settings for babel-preset-env:

{
  "presets": [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions"]
      }
    }]
  ]
}

Now, I see we set the Babel settings in rollup.config.js:

UMD settings part:

{
		entry: 'src/main.js',
		dest: pkg.browser,
		format: 'umd',
		moduleName: 'howLongUntilLunch',
		plugins: [
			resolve(), // so Rollup can find `ms`
			commonjs(), // so Rollup can convert `ms` to an ES module
			babel({
				exclude: ['node_modules/**']
			})
		]
	}

My question: why does babel-preset-env have no settings in UMD part for the target environment? Is it because we want to make the module the most universal and therefore we apply the maximum transpiling?

TypeScript example using wrong plugin packages

Got directed to this repo from the rollup website.
Trying to figure out how to use Rollup to ship a TypeScript React component library as ESM.

It looks like the packages being used in the TypeScript example are wrong:

https://github.com/rollup/rollup-starter-lib/blob/typescript/package.json#L13-L15

The latest versions of plugins have been moved under the @rollup organization on npm and the example should be updated to use those packages.

https://github.com/rollup/plugins/tree/master/packages/typescript

About update to @rollup/plugin-typescript

Hello there, I want to upate to @rollup/plugin-typescript from rollup-plugin-typescript, but found it only compile main.ts but not the lunchtime.ts, millisecondsUntil.ts (as in this repo) in the cjs format.

I have look through https://rollupjs.org/guide but do not found anything to solve this.

So, I want to know if there is any special configuaration about this problem?

An in-range update of @rollup/plugin-node-resolve is breaking the build 🚨

The devDependency @rollup/plugin-node-resolve was updated from 7.0.0 to 7.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@rollup/plugin-node-resolve is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.9.2 to 1.9.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v1.9.3

2019-04-10

Bug Fixes

  • Simplify return expressions that are evaluated before the surrounding function is bound (#2803)

Pull Requests

  • #2803: Handle out-of-order binding of identifiers to improve tree-shaking (@lukastaegert)
Commits

The new version differs by 3 commits.

  • 516a06d 1.9.3
  • a5526ea Update changelog
  • c3d73ff Handle out-of-order binding of identifiers to improve tree-shaking (#2803)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Should be `dist` commited?

Hi, thanks for great kick in! but..

I think that dist should be ignored from version control, like build is excluded in many others projects.

I expected that there will be more opinions, but I did't found it there, no much opened issues, no debates.. so I'm trying kick up this with this one 🙂

tslib usage seems off

First time coming across tslib in this project (thanks). From its README:

This is a runtime library for TypeScript that contains all of the TypeScript helper functions.

For optimized bundles with TypeScript, you should absolutely consider using tslib and --importHelpers.

So it seems like the existing package.json for this project should be updated to put tslib under dependencies (not devDependencies), and that tsconfig.json should have importHelpers uncommented to set it to true.

Would probably add some docs in README.md to the effect that e.g. if your lib is small (e.g. you only have one module), then you're better off just removing tslib and the importHelpers option.

What do you think? Do you want a PR for this?

Cheers

Bug: Add @rollup/plugin-json to import JSON files

The example rollup.config.js imports the package.json

Not sure if this is a new requirement from rollup. But this is seemingly not possible without adding @rollup/plugin-json.

Heres the error:

Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
../../node_modules/iconv-lite/encodings/tables/gb18030-ranges.json (1:9)
1: {"uChars":[128,165,169,178,184,216,226,235,238,244,248,251,253,258,276,284,300,325,329,334,364,463,465,467,469,471,473,475,477,506,594,610,712,716,730,930,938,962,970,1026,1104,1106,8209,8215,8218,8222,8231,8241,8244,8246,8252,8365,8452,8454,8458,8471,8482,8556,8570,8596,8602,8713,8720,8722,8726,8731,8737,8740,8742,8748,8751,8760,8766,8777,8781,8787,8802,8808,8816,8

Am I using `external` incorrectly?

Hello :)

TLDR; I've used this project to bundle my plugin, but I can't seem to reference it in a demo project

I'm upgrading a project of mine, a Vue JS plugin called VueSource to use Rollup as the bundler.

I'm using this project as the starting point, as it seems the most likely candidate I've found to successfully create a module I can use in other projects, and publish to NPM.

The current branch for this upgrade is:

To make sure the plugin is robust before publishing, I generally host a demo project side-by-side with the plugin, using Vue CLI to compile the web app and NPM Link to see changes live as I update the plugin:

+- VueSource
    +- vue-source
    +- vue-source-demo

The current branch for this demo project is:

This setup has worked very successfully in other projects using Webpack.

However, although I've got the bundling, linking and compiling working, when the browser loads the demo webapp, the plugin is undefined:

image

In the image above the ../vue-source link seems curious to me, as I would have expected to have seen it in node_modules - where it actually is.

At first I thought this might be an NPM link problem, but now I am thinking this has more to do with Rollup's external option.

I confirmed this by adding a breakpoint to both files, and it seems that both actually load so I'm suspecting that the reason that the module is undefined has something to do with this, though I'm not sure.

Can anyone shed any light?

Thanks.

An in-range update of @rollup/plugin-commonjs is breaking the build 🚨

The devDependency @rollup/plugin-commonjs was updated from 11.0.1 to 11.0.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@rollup/plugin-commonjs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

rollup version is too old

If I use lates rollup 3.17.2 (now is 1.29.0), then I run yarn run dev, the error throws:

rollup-starter-lib [master] % yarn run build
yarn run v1.22.19
$ rollup -c
(node:70006) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/Users/hwf/source/rollup-starter-lib/rollup.config.js:3
import pkg from './package.json';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:203:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async getConfigFileExport (/Users/hwf/source/rollup-starter-lib/node_modules/rollup/dist/shared/loadConfigFile.js:432:17)
    at async Object.loadConfigFile (/Users/hwf/source/rollup-starter-lib/node_modules/rollup/dist/shared/loadConfigFile.js:391:59)

Seems like need do this if want use rollup3.x:

rollup/rollup#4446 (comment)

rollup/rollup#3481 (comment)

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 0.67.3 to 0.67.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.27.6 to 1.27.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v1.27.7

2019-12-01

Bug Fixes

  • Fix a scenario where a reassignments to computed properties were not tracked (#3267)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.