Skip to content

Commit 6c9e016

Browse files
committed
Run rollup twice to generate two self-contained modules: index.js (the default export) and jsx.js (the test-style renderer)
1 parent 103c2cc commit 6c9e016

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"main": "dist/index.js",
77
"jsnext:main": "src/index.js",
88
"scripts": {
9-
"build": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
9+
"build": "npm run -s transpile && npm run -s transpile:jsx",
10+
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
11+
"transpile:jsx": "ENTRY=jsx rollup -c rollup.config.js -m dist/jsx.js.map -f umd -n $npm_package_amdName src/jsx.js -o dist/jsx.js",
1012
"test": "eslint {src,test} && mocha --compilers js:babel-register test/**/*.js",
1113
"prepublish": "npm run build",
1214
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
@@ -42,12 +44,14 @@
4244
"babel-preset-stage-0": "^6.5.0",
4345
"babel-register": "^6.9.0",
4446
"chai": "^3.5.0",
45-
"eslint": "^3.1.1",
47+
"eslint": "^3.2.2",
4648
"mocha": "^3.0.0",
4749
"preact": "^5.5.0",
48-
"rollup": "^0.34.2",
50+
"rollup": "^0.34.3",
4951
"rollup-plugin-babel": "^2.6.1",
52+
"rollup-plugin-commonjs": "^3.3.1",
5053
"rollup-plugin-memory": "^1.0.0",
54+
"rollup-plugin-node-resolve": "^2.0.0",
5155
"sinon": "^1.17.5",
5256
"sinon-chai": "^2.8.0"
5357
},

rollup.config.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import fs from 'fs';
2+
import nodeResolve from 'rollup-plugin-node-resolve';
3+
import commonjs from 'rollup-plugin-commonjs';
24
import memory from 'rollup-plugin-memory';
35
import babel from 'rollup-plugin-babel';
46

57
let babelRc = JSON.parse(fs.readFileSync('./.babelrc'));
68

9+
let entry = process.env.ENTRY || 'index';
10+
711
export default {
8-
entry: 'src/index.js',
12+
entry: 'src/'+entry+'.js',
913
exports: 'default',
1014
useStrict: false,
1115
external: ['preact'],
1216
plugins: [
1317
memory({
14-
path: 'src/index.js',
15-
contents: "export { default } from './index';"
18+
path: 'src/'+entry+'.js',
19+
contents: "export { default } from './"+entry+"';"
20+
}),
21+
nodeResolve({
22+
skip: ['preact'],
23+
main: true
1624
}),
25+
commonjs(),
1726
babel({
1827
babelrc: false,
1928
comments: false,

test/jsx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, shallowRender } from '../src';
1+
import render from '../src/jsx';
22
import { h, Component } from 'preact';
33
import chai, { expect } from 'chai';
44
import { spy, match } from 'sinon';
@@ -11,7 +11,7 @@ function dedent([str]) {
1111
}
1212

1313
describe('jsx', () => {
14-
let renderJsx = jsx => render(jsx, {}, { jsx:true, xml:true, pretty:' ' }).replace(/ {2}/g, '\t');
14+
let renderJsx = jsx => render(jsx).replace(/ {2}/g, '\t');
1515

1616
it('should render as JSX', () => {
1717
let rendered = renderJsx(

0 commit comments

Comments
 (0)