Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Build umd with rollup (#341)
Browse files Browse the repository at this point in the history
* Build umd with rollup

* Tidy up

* Fix scripts lint

* Fix deps
  • Loading branch information
TrySound authored and istarkov committed Apr 8, 2017
1 parent 06e9583 commit 47d4ec7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 99 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-syntax-jsx": "^6.8.0",
"babel-plugin-syntax-trailing-function-commas": "^6.8.0",
"babel-plugin-transform-async-to-generator": "^6.8.0",
Expand Down Expand Up @@ -72,11 +72,16 @@
"react-dom": "^15.0.0",
"readline-sync": "^1.2.21",
"rimraf": "^2.4.3",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
"rx": "^4.1.0",
"rxjs": "^5.0.0-beta.9",
"shelljs": "^0.6.0",
"sinon": "^1.17.1",
"webpack": "^1.12.0",
"xstream": "^5.0.5"
},
"devEngines": {
Expand Down
57 changes: 57 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const nodeResolve = require('rollup-plugin-node-resolve')
const babel = require('rollup-plugin-babel')
const replace = require('rollup-plugin-replace')
const commonjs = require('rollup-plugin-commonjs')

module.exports = {
external: [
'react'
],
globals: {
react: 'React'
},
// Set library in release script
// moduleName: 'Recompose',
format: 'umd',
plugins: [
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**',
babelrc: false,
plugins: [
'babel-plugin-transform-function-bind',
'babel-plugin-transform-class-constructor-call',
['babel-plugin-transform-class-properties', { loose: true }],
'babel-plugin-transform-export-extensions',
'babel-plugin-syntax-trailing-function-commas',
'babel-plugin-transform-object-rest-spread',
'babel-plugin-transform-async-to-generator',

'babel-plugin-transform-react-jsx',
'babel-plugin-syntax-jsx',
'babel-plugin-transform-react-display-name',

['babel-plugin-transform-es2015-template-literals', { loose: true }],
'babel-plugin-transform-es2015-literals',
'babel-plugin-transform-es2015-function-name',
'babel-plugin-transform-es2015-arrow-functions',
'babel-plugin-transform-es2015-block-scoped-functions',
['babel-plugin-transform-es2015-classes', { loose: true }],
'babel-plugin-transform-es2015-shorthand-properties',
['babel-plugin-transform-es2015-computed-properties', { loose: true }],
['babel-plugin-transform-es2015-spread', { loose: true }],
'babel-plugin-transform-es2015-parameters',
['babel-plugin-transform-es2015-destructuring', { loose: true }],
'babel-plugin-transform-es2015-block-scoping',
'babel-plugin-transform-regenerator',
'babel-plugin-external-helpers'
]
}),
commonjs(),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}
14 changes: 7 additions & 7 deletions scripts/getPackageNames.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import fs from 'fs'
import path from 'path'
const fs = require('fs')
const path = require('path')

export const PACKAGES_SRC_DIR = './src/packages'
export const PACKAGES_OUT_DIR = './lib/packages'
exports.PACKAGES_SRC_DIR = './src/packages'
exports.PACKAGES_OUT_DIR = './lib/packages'

let names

export const getPackageNames = () => {
exports.getPackageNames = () => {
if (!names) {
names = fs.readdirSync(PACKAGES_SRC_DIR).filter(
file => fs.statSync(path.resolve(PACKAGES_SRC_DIR, file)).isDirectory()
names = fs.readdirSync(exports.PACKAGES_SRC_DIR).filter(file =>
fs.statSync(path.resolve(exports.PACKAGES_SRC_DIR, file)).isDirectory()
)
}
return names
Expand Down
6 changes: 3 additions & 3 deletions scripts/installNestedPackageDeps.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import { exec } from 'shelljs'
import { getPackageNames, PACKAGES_SRC_DIR } from './getPackageNames.js'
const path = require('path')
const { exec } = require('shelljs')
const { getPackageNames, PACKAGES_SRC_DIR } = require('./getPackageNames.js')

const packageNames = getPackageNames()

Expand Down
89 changes: 37 additions & 52 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import fs from 'fs'
import path from 'path'
import { exec, exit, rm, cp, test } from 'shelljs'
import chalk from 'chalk'
import { flowRight as compose } from 'lodash'
import readline from 'readline-sync'
import semver from 'semver'
import glob from 'glob'
import { pascalCase } from 'change-case'
import webpack from 'webpack'
import webpackBaseConfig from '../webpack.config'
const fs = require('fs')
const path = require('path')
const { exec, exit, rm, cp, test } = require('shelljs')
const chalk = require('chalk')
const { flowRight: compose } = require('lodash')
const readline = require('readline-sync')
const semver = require('semver')
const glob = require('glob')
const { pascalCase } = require('change-case')
const { rollup } = require('rollup')
const uglify = require('rollup-plugin-uglify')
const rollupBaseConfig = require('../rollup.config')

const BIN = './node_modules/.bin'

import {
const {
PACKAGES_SRC_DIR,
PACKAGES_OUT_DIR,
getPackageNames
} from './getPackageNames'
} = require('./getPackageNames')

const BASE_PACKAGE_LOC = '../src/basePackage.json'

Expand Down Expand Up @@ -61,8 +62,8 @@ const run = async () => {
(semver.valid(nextVersion) && semver.gt(nextVersion, version))
)) {
nextVersion = readline.question(
`Must provide a valid version that is greater than ${version}, `
+ `or leave blank to skip: `
`Must provide a valid version that is greater than ${version}, ` +
`or leave blank to skip: `
)
}

Expand All @@ -89,7 +90,10 @@ const run = async () => {
ignore: `${sourceDir}/node_modules/**/*.js`
}).map(to => path.relative(sourceDir, to))

exec(`cd ${sourceDir} && ${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} --out-dir ${path.resolve(outDir)}`)
exec(
`cd ${sourceDir} && ${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} ` +
`--out-dir ${path.resolve(outDir)}`
)

log('Copying additional project files...')
const additionalProjectFiles = [
Expand All @@ -110,52 +114,33 @@ const run = async () => {
version: nextVersion,
...require(BASE_PACKAGE_LOC),
...require(path.resolve(sourceDir, 'package.json')),
private: undefined,
private: undefined
}

writeFile(
path.resolve(outDir, 'package.json'),
JSON.stringify(packageConfig, null, 2)
)

const buildWebpack = config => {
return new Promise((resolve, reject) => {
log(`Building ${config.output.filename}...`)
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
// log(`${config.output.filename} is ${stats.chunks[0].size}`)
writeFile(
path.resolve(outDir, `build/${config.output.filename}.stats.json`),
JSON.stringify(stats.toJson())
)
resolve()
})
})
const buildRollup = config => {
log(`Building ${config.dest}...`)
return rollup(config).then(bundle => bundle.write(config))
}

const libraryName = pascalCase(packageName)
const webpackConfig = {
...webpackBaseConfig,
entry: [path.resolve(sourceDir, 'index.js')],
output: {
...webpackBaseConfig.output,
library: libraryName,
path: `${outDir}/build`,
filename: `${libraryName}.js`
}
const rollupConfig = {
...rollupBaseConfig,
entry: path.resolve(sourceDir, 'index.js'),
moduleName: libraryName,
dest: `${outDir}/build/${libraryName}.js`
}
const webpackMinConfig = {
...webpackConfig,
output: {
...webpackConfig.output,
filename: `${libraryName}.min.js`
},
const rollupMinConfig = {
...rollupConfig,
dest: `${outDir}/build/${libraryName}.min.js`,
plugins: [
...webpackConfig.plugins,
new webpack.optimize.UglifyJsPlugin({
compressor: {
...rollupConfig.plugins,
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
Expand All @@ -167,8 +152,8 @@ const run = async () => {
}

await Promise.all([
buildWebpack(webpackConfig),
buildWebpack(webpackMinConfig),
buildRollup(rollupConfig),
buildRollup(rollupMinConfig)
])

log(`About to publish ${packageName}@${nextVersion} to npm.`)
Expand Down
35 changes: 0 additions & 35 deletions webpack.config.js

This file was deleted.

0 comments on commit 47d4ec7

Please sign in to comment.