diff --git a/bsconfig.json b/bsconfig.json index ebef2d3..491890f 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -6,6 +6,7 @@ "name" : "reason-react-example", "reason" : { "react-jsx" : true}, "bs-dependencies": ["reason-react", "reason-js"], + "package-specs": ["es6", "commonjs"], "sources": [ { "dir": "src", diff --git a/package.json b/package.json index 8b51aa7..1a2e01b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "start": "bsb -make-world -w", "build": "webpack -w", + "rollup": "node ./rollup", "clean": "bsb -clean-world" }, "keywords": [], @@ -24,6 +25,12 @@ }, "devDependencies": { "bs-platform": "^1.6.0", - "webpack": "^1.14.0" + "rollup": "^0.41.6", + "rollup-plugin-commonjs": "^8.0.2", + "rollup-plugin-node-resolve": "^3.0.0", + "rollup-plugin-replace": "^1.1.1", + "rollup-watch": "^3.2.2", + "webpack": "^2.3.2", + "webpack-dev-server": "^2.4.2" } } diff --git a/rollup.js b/rollup.js new file mode 100644 index 0000000..fced210 --- /dev/null +++ b/rollup.js @@ -0,0 +1,72 @@ +const rollup = require('rollup').rollup; +const commonjs = require('rollup-plugin-commonjs'); +const nodeResolve = require('rollup-plugin-node-resolve'); +const replace = require('rollup-plugin-replace'); +const path = require('path'); + +const config = { + entry: { + simple: './lib/es6/src/simple/simpleRoot.js', + logo: './lib/es6/src/logo/logoRoot.js', + // TODO: enable these + // todomvc: './lib/es6/src/todomvc/app.js', + // interop: './src/interop/interopRoot.js', + }, +}; +Object.keys(config.entry) + .forEach(key => { + const entry = config.entry[key]; + rollup({ + entry: entry, // 'lib/es6/src/' + entry + '.js', + plugins: [ + replace({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'), + }), + nodeResolve({ + jsnext: true, + main: true, + module: true, + }), + + commonjs({ + // non-CommonJS modules will be ignored, but you can also + // specifically include/exclude files + include: 'node_modules/**', + // exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ], + + // if true then uses of `global` won't be dealt with by this plugin + ignoreGlobal: false, + preferBuiltins: true, + + // if false then skip sourceMap generation for CommonJS modules + sourceMap: false, + + // explicitly specify unresolvable named exports + // (see below for more details) + namedExports: { + 'react': [ + 'createClass', + 'createElement', + ], + 'react-dom': [ + 'render' + ] + }, + + // sometimes you have to leave require statements + // unconverted. Pass an array containing the IDs + // or a `id => boolean` function. Only use this + // option if you know what you're doing! + // ignore: [ 'conditional-runtime-dependency' ] + }), + ] + }) + .then((result) => { + // const filename = last(entry.split('/')); + return result.write({ + dest: path.join(__dirname, 'rollupOutputs', key + '.js'), + format: 'iife' + }); + }) + .catch(console.log); + });