Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

[Proof of Concept]: build(rollup): add experimental mode to use rollup #782

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 gulp -- build_dist_client",
"test": "gulp test",
"gulp": "gulp"
},
Expand Down Expand Up @@ -78,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",
Expand All @@ -101,6 +103,11 @@
"postcss-cli": "^2.6.0",
"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-globals": "^1.0.7",
"rollup-plugin-node-resolve": "^2.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update packages to latest

"stylelint": "^7.2.0",
"tslint": "3.15.0-dev.0",
"typescript": "2.1.0-dev.20160918",
Expand Down
100 changes: 100 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/// <reference path='./typings/index.d.ts'/>

'use strict';

const assert = require('assert');
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';

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');

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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use https://github.com/rollup/rollup-plugin-replace instead of these?


// 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 = {
entry: KAREN_ENTRY_POINT,
dest: path.resolve(KAREN_CLIENT_DIST_DIR, 'karen.js'),
format: 'cjs',
exports: 'none',
useStrict: true,
sourceMap: true,
treeshake: true,

plugins: [
// https://github.com/rollup/rollup-plugin-node-resolve
nodeResolve({
module: true,
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
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
babel({
exclude: 'node_modules/**',
presets: babelPresets,
plugins: babelPlugins,
}),

// https://github.com/calvinmetcalf/rollup-plugin-node-builtins
nodeGlobals(),
]
};
15 changes: 13 additions & 2 deletions tools/build/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down