From fc16abf9974ecd66a77e6d68d2e27c1c9a7737d0 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Sun, 4 Sep 2016 23:57:45 +0900 Subject: [PATCH 1/7] build(rollup): add experimental 'npm run rollup' --- package.json | 2 ++ rollup.config.js | 28 ++++++++++++++++++++++++++++ tools/build/script.js | 15 +++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 rollup.config.js diff --git a/package.json b/package.json index ab42d885..98befb25 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "build_production": "cross-env NODE_ENV=production npm run build", "build_development": "cross-env NODE_ENV=development npm run build", "build": "gulp build", + "rollup": "cross-env ENABLE_ROLLUP=1 npm run build", "test": "gulp test", "gulp": "gulp" }, @@ -101,6 +102,7 @@ "postcss-cli": "^2.6.0", "postcss-custom-properties": "^5.0.1", "postcss-import": "^8.1.2", + "rollup": "^0.35.14", "stylelint": "^7.2.0", "tslint": "3.15.0-dev.0", "typescript": "2.1.0-dev.20160918", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..e68335f6 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,28 @@ +/// + +'use strict'; + +const assert = require('assert'); +const path = require('path'); + +const isRelease = process.env.NODE_ENV === 'production'; + +const KAREN_ENTRY_POINT = process.env.KAREN_ENTRY_POINT; +assert.ok(!!KAREN_ENTRY_POINT, 'not found process.env.KAREN_ENTRY_POINT'); + +const KAREN_CLIENT_DIST_DIR = process.env.KAREN_CLIENT_DIST_DIR; +assert.ok(!!KAREN_CLIENT_DIST_DIR, 'not found process.env.KAREN_CLIENT_DIST_DIR'); + +// https://github.com/rollup/rollup/wiki/JavaScript-API +// https://github.com/rollup/rollup/wiki/Command-Line-Interface +module.exports = { + entry: KAREN_ENTRY_POINT, + dest: path.resolve(KAREN_CLIENT_DIST_DIR, 'karen.js'), + format: 'cjs', + exports: 'none', + useStrict: true, + sourceMap: true, + treeshake: true, + + plugins: [] +}; diff --git a/tools/build/script.js b/tools/build/script.js index 0a44f7d4..80aaba58 100644 --- a/tools/build/script.js +++ b/tools/build/script.js @@ -39,8 +39,19 @@ const { spawnChildProcess, assertReturnCode } = require('../spawn'); * @returns {NodeJS.ReadableStream} */ function runLinkerForClient(cwd, nodeModDir, entryPoint, distDir) { - const bin = path.resolve(nodeModDir, './.bin', getSuffixedCommandName('./webpack')); - const args = []; + let bin = ''; + let args = []; + if (!!process.env.ENABLE_ROLLUP) { + bin = path.resolve(nodeModDir, './.bin', getSuffixedCommandName('./rollup')); + args = [ + '-c', + path.resolve(cwd, 'rollup.config.js'), + ]; + } + else { + bin = path.resolve(nodeModDir, './.bin', getSuffixedCommandName('./webpack')); + } + const option = { cwd, stdio: 'inherit', From 97a5faa780687eac1410a000ed9f925c54917e47 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 5 Sep 2016 00:08:44 +0900 Subject: [PATCH 2/7] build(rollup): enable to import commonjs installed by npm --- package.json | 2 ++ rollup.config.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 98befb25..9f63c8d1 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,8 @@ "postcss-custom-properties": "^5.0.1", "postcss-import": "^8.1.2", "rollup": "^0.35.14", + "rollup-plugin-commonjs": "^5.0.3", + "rollup-plugin-node-resolve": "^2.0.0", "stylelint": "^7.2.0", "tslint": "3.15.0-dev.0", "typescript": "2.1.0-dev.20160918", diff --git a/rollup.config.js b/rollup.config.js index e68335f6..6797e567 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,6 +5,9 @@ const assert = require('assert'); const path = require('path'); +const nodeResolve = require('rollup-plugin-node-resolve'); +const commonjs = require('rollup-plugin-commonjs'); + const isRelease = process.env.NODE_ENV === 'production'; const KAREN_ENTRY_POINT = process.env.KAREN_ENTRY_POINT; @@ -24,5 +27,19 @@ module.exports = { sourceMap: true, treeshake: true, - plugins: [] + plugins: [ + // https://github.com/rollup/rollup-plugin-node-resolve + nodeResolve({ + module: true, + main: true, + browser: true, // for browser + preferBuiltins: false, // linking for browser + }), + + // https://github.com/rollup/rollup-plugin-commonjs + commonjs({ + include: 'node_modules/**', + ignoreGlobal: true, + }), + ] }; From e78ba6649174fc04e83f24e4fd868baeddc26ff1 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 5 Sep 2016 00:24:18 +0900 Subject: [PATCH 3/7] build(rollup): enable to import 'jsx' file. --- rollup.config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 6797e567..2bd701fc 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -34,6 +34,10 @@ module.exports = { main: true, browser: true, // for browser preferBuiltins: false, // linking for browser + + // rollup does not have 'extensions' option, + // so we need to specify this option at here to import jsx file. + extensions: ['.js', '.jsx'], }), // https://github.com/rollup/rollup-plugin-commonjs From 6126c5ce592e2dda6d241997a35552c04d01701d Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 5 Sep 2016 00:29:34 +0900 Subject: [PATCH 4/7] build(rollup): enable babel transform --- package.json | 2 ++ rollup.config.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/package.json b/package.json index 9f63c8d1..5f904dd3 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "babel-cli": "^6.14.0", "babel-core": "^6.14.0", "babel-loader": "^6.2.5", + "babel-plugin-external-helpers": "^6.8.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", "babel-plugin-transform-inline-environment-variables": "^6.8.0", "babel-plugin-transform-node-env-inline": "^6.8.0", @@ -103,6 +104,7 @@ "postcss-custom-properties": "^5.0.1", "postcss-import": "^8.1.2", "rollup": "^0.35.14", + "rollup-plugin-babel": "^2.6.1", "rollup-plugin-commonjs": "^5.0.3", "rollup-plugin-node-resolve": "^2.0.0", "stylelint": "^7.2.0", diff --git a/rollup.config.js b/rollup.config.js index 2bd701fc..ac8ead3a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -7,6 +7,7 @@ const path = require('path'); const nodeResolve = require('rollup-plugin-node-resolve'); const commonjs = require('rollup-plugin-commonjs'); +const babel = require('rollup-plugin-babel'); const isRelease = process.env.NODE_ENV === 'production'; @@ -16,6 +17,42 @@ assert.ok(!!KAREN_ENTRY_POINT, 'not found process.env.KAREN_ENTRY_POINT'); const KAREN_CLIENT_DIST_DIR = process.env.KAREN_CLIENT_DIST_DIR; assert.ok(!!KAREN_CLIENT_DIST_DIR, 'not found process.env.KAREN_CLIENT_DIST_DIR'); +const babelPresets = [ +]; + +let babelPlugins = [ + // For our target browsers, we need not some transforms. + + // es2016 level + 'babel-plugin-transform-exponentiation-operator', + // es2017 level + 'babel-plugin-syntax-trailing-function-commas', + 'babel-plugin-transform-async-to-generator', + + // for React + 'syntax-jsx', + 'transform-react-jsx', + + // some utilitis + 'transform-inline-environment-variables', + 'transform-node-env-inline', + + // to remove duplicated helper methods inserted by babel. + 'external-helpers', +]; + +if (isRelease) { + babelPlugins = babelPlugins.concat([ + 'transform-react-constant-elements', + 'transform-react-inline-elements', + ]); +} +else { + babelPlugins = babelPlugins.concat([ + 'transform-react-jsx-source', + ]); +} + // https://github.com/rollup/rollup/wiki/JavaScript-API // https://github.com/rollup/rollup/wiki/Command-Line-Interface module.exports = { @@ -45,5 +82,12 @@ module.exports = { include: 'node_modules/**', ignoreGlobal: true, }), + + // https://github.com/rollup/rollup-plugin-babel + babel({ + exclude: 'node_modules/**', + presets: babelPresets, + plugins: babelPlugins, + }), ] }; From 2adca99163aeb9148036383de87abe5824129466 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 5 Sep 2016 00:44:21 +0900 Subject: [PATCH 5/7] build(rollup): inject node's global objects --- package.json | 1 + rollup.config.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index 5f904dd3..b8717a56 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "rollup": "^0.35.14", "rollup-plugin-babel": "^2.6.1", "rollup-plugin-commonjs": "^5.0.3", + "rollup-plugin-node-globals": "^1.0.7", "rollup-plugin-node-resolve": "^2.0.0", "stylelint": "^7.2.0", "tslint": "3.15.0-dev.0", diff --git a/rollup.config.js b/rollup.config.js index ac8ead3a..f6a04baf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,6 +8,7 @@ const path = require('path'); const nodeResolve = require('rollup-plugin-node-resolve'); const commonjs = require('rollup-plugin-commonjs'); const babel = require('rollup-plugin-babel'); +const nodeGlobals = require('rollup-plugin-node-globals'); const isRelease = process.env.NODE_ENV === 'production'; @@ -89,5 +90,8 @@ module.exports = { presets: babelPresets, plugins: babelPlugins, }), + + // https://github.com/calvinmetcalf/rollup-plugin-node-builtins + nodeGlobals(), ] }; From d6b058c2bb7225cda3f93b32e6b20447839cb236 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 19 Sep 2016 01:59:11 +0900 Subject: [PATCH 6/7] for debugging --- gulpfile.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 0f1fb132..f3ea772c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -130,7 +130,7 @@ gulp.task('clean_test_cache_server', () => del(TEST_CACHE_SERVER)); */ gulp.task('build', ['lint', 'build_dist_client', 'build_dist_server', 'build_dist_style', 'build_dist_legacy_lib']); -gulp.task('build_dist_client', ['clean_dist_client', 'build_obj_client', 'build_obj_lib'], function () { +gulp.task('build_dist_client', ['clean_dist_client', 'build_obj_client', 'build_obj_lib', 'build_dist_legacy_lib'], function () { const root = './karen.js'; const ENTRY_POINT = path.resolve(OBJ_CLIENT, root); diff --git a/package.json b/package.json index b8717a56..05f9ea49 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build_production": "cross-env NODE_ENV=production npm run build", "build_development": "cross-env NODE_ENV=development npm run build", "build": "gulp build", - "rollup": "cross-env ENABLE_ROLLUP=1 npm run build", + "rollup": "cross-env ENABLE_ROLLUP=1 npm run gulp -- build_dist_client", "test": "gulp test", "gulp": "gulp" }, From 9737337d6fa1916c55c5e8a20cf307d1b2644077 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 19 Sep 2016 04:06:49 +0900 Subject: [PATCH 7/7] fix(rollup): adhoc fix to link with option-t --- rollup.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index f6a04baf..cee3582b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -82,6 +82,9 @@ module.exports = { commonjs({ include: 'node_modules/**', ignoreGlobal: true, + namedExports: { + 'node_modules/option-t/src/index.js': ['Some', 'None', 'OptionBase'], // FIXME + }, }), // https://github.com/rollup/rollup-plugin-babel