Skip to content

Commit d89fdcf

Browse files
Andaristdanilowoz
authored andcommitted
Refactored build infrastructure (#68)
1 parent 4c801f2 commit d89fdcf

File tree

9 files changed

+244
-133
lines changed

9 files changed

+244
-133
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015", "stage-2", "react", "flow"]
2+
"presets": ["./.babelrc.js"]
33
}

.babelrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { NODE_ENV, BABEL_ENV } = process.env
2+
const modules = BABEL_ENV === 'cjs' || NODE_ENV === 'test' ? 'commonjs' : false
3+
const loose = true
4+
5+
module.exports = {
6+
presets: [
7+
["env", { modules, loose, targets: { uglify: true } }],
8+
'stage-2',
9+
'react',
10+
'flow',
11+
]
12+
}

.npmignore

Lines changed: 0 additions & 19 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
{
22
"name": "react-content-loader",
33
"version": "2.0.0",
4-
"description":
5-
"React component that uses SVG to create a collection of loaders which simulates the structure of the content that will be loaded, similar to Facebook cards loaders.",
4+
"description": "React component that uses SVG to create a collection of loaders which simulates the structure of the content that will be loaded, similar to Facebook cards loaders.",
65
"repository": {
76
"type": "git",
87
"url": "https://github.com/danilowoz/react-content-loader"
98
},
109
"author": "Danilo Woznica",
1110
"license": "MIT",
12-
"jsnext:main": "index",
11+
"main": "dist/react-content-loader.cjs.js",
12+
"module": "dist/react-content-loader.es.js",
13+
"jsnext:main": "dist/react-content-loader.es.js",
1314
"bugs": {
1415
"url": "https://github.com/danilowoz/react-content-loader/issues"
1516
},
1617
"homepage": "https://github.com/danilowoz/react-content-loader",
17-
"keywords": ["react", "facebook-style", "loader", "loading", "content", "svg"],
18+
"keywords": [
19+
"react",
20+
"facebook-style",
21+
"loader",
22+
"loading",
23+
"content",
24+
"svg"
25+
],
26+
"files": [
27+
"dist"
28+
],
29+
"sideEffects": false,
1830
"options": {
1931
"mocha": "--require scripts/mocha_runner ./tests/**/*.js ./tests/*.js"
2032
},
2133
"scripts": {
22-
"watch":
23-
"babel --plugins transform-es2015-modules-umd src --watch --ignore tests --out-dir ./dist",
24-
"build": "babel --plugins transform-es2015-modules-umd src --ignore tests --out-dir ./dist",
34+
"watch": "npm run build -- --watch",
35+
"build": "rollup -c",
2536
"lint": "eslint 'src/**/*.js'",
2637
"prettier": "prettier --write 'src/**/*.{js,jsx,json,css}'",
27-
"testonly": "mocha $npm_package_options_mocha",
38+
"testonly": "cross-env NODE_ENV=test mocha $npm_package_options_mocha",
2839
"test": "npm run lint && npm run testonly && npm run flow",
2940
"test-watch": "npm run testonly -- --watch --watch-extensions js",
3041
"storybook": "start-storybook -p 6006",
@@ -34,17 +45,18 @@
3445
},
3546
"devDependencies": {
3647
"@storybook/react": "^3.1.9",
37-
"babel-cli": "^6.6.4",
3848
"babel-core": "^6.7.4",
3949
"babel-eslint": "^8.0.2",
50+
"babel-plugin-external-helpers": "^6.22.0",
4051
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
4152
"babel-polyfill": "^6.7.4",
42-
"babel-preset-es2015": "^6.6.0",
53+
"babel-preset-env": "^1.6.1",
4354
"babel-preset-flow": "^6.23.0",
4455
"babel-preset-react": "^6.5.0",
4556
"babel-preset-stage-2": "^6.5.0",
4657
"chai": "^4.1.2",
4758
"chai-enzyme": "^1.0.0-beta.0",
59+
"cross-env": "^5.1.3",
4860
"enzyme": "^3.2.0",
4961
"enzyme-adapter-react-16": "^1.1.0",
5062
"eslint": "^4.12.0",
@@ -61,13 +73,14 @@
6173
"react": "^16.1.1",
6274
"react-addons-test-utils": "^15.0.0",
6375
"react-dom": "^16.1.1",
64-
"sinon": "^4.1.2",
65-
"uuid": "^3.0.1"
76+
"rollup": "0.53",
77+
"rollup-plugin-babel": "^3.0.3",
78+
"rollup-plugin-replace": "^2.0.0",
79+
"rollup-plugin-uglify": "^2.0.1",
80+
"sinon": "^4.1.2"
6681
},
6782
"peerDependencies": {
6883
"react": "^15.0.0-0 || ^16.0.0-0"
6984
},
70-
"dependencies": {
71-
"babel-runtime": "^6.6.1"
72-
}
85+
"dependencies": {}
7386
}

rollup.config.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import babel from 'rollup-plugin-babel'
2+
import replace from 'rollup-plugin-replace'
3+
import uglify from 'rollup-plugin-uglify'
4+
import pkg from './package.json'
5+
6+
const mergeAll = (objs) => Object.assign({}, ...objs)
7+
8+
const commonPlugins = [
9+
babel({
10+
exclude: 'node_modules/**',
11+
plugins: ['external-helpers']
12+
}),
13+
]
14+
15+
const configBase = {
16+
input: 'src/index.js',
17+
output: {
18+
exports: 'named'
19+
},
20+
external: [
21+
...Object.keys(pkg.dependencies || {}),
22+
...Object.keys(pkg.peerDependencies || {})
23+
],
24+
plugins: commonPlugins
25+
}
26+
27+
const umdConfig = mergeAll([
28+
configBase,
29+
{
30+
output: mergeAll([
31+
configBase.output,
32+
{
33+
file: `dist/${pkg.name}.js`,
34+
format: 'umd',
35+
name: 'ContentLoader',
36+
globals: {
37+
react: 'React',
38+
'react-dom': 'ReactDOM'
39+
},
40+
41+
}
42+
]),
43+
external: Object.keys(pkg.peerDependencies || {})
44+
}
45+
])
46+
47+
const devUmdConfig = mergeAll([
48+
umdConfig,
49+
{
50+
plugins: umdConfig.plugins.concat(
51+
replace({
52+
'process.env.NODE_ENV': JSON.stringify('development')
53+
})
54+
)
55+
}
56+
])
57+
58+
const prodUmdConfig = mergeAll([
59+
umdConfig,
60+
{
61+
output: mergeAll([
62+
umdConfig.output,
63+
{ file: umdConfig.output.file.replace(/\.js$/, '.min.js') }
64+
])
65+
},
66+
{
67+
plugins: umdConfig.plugins.concat(
68+
replace({
69+
'process.env.NODE_ENV': JSON.stringify('production')
70+
}),
71+
uglify({
72+
compress: {
73+
pure_getters: true,
74+
unsafe: true,
75+
unsafe_comps: true,
76+
}
77+
})
78+
)
79+
}
80+
])
81+
82+
const webConfig = mergeAll([
83+
configBase,
84+
{
85+
output: [
86+
mergeAll([configBase.output, { file: pkg.module, format: 'es' }]),
87+
mergeAll([configBase.output, { file: pkg.main, format: 'cjs' }])
88+
]
89+
}
90+
])
91+
92+
export default [devUmdConfig, prodUmdConfig, webConfig]

src/Wrap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@flow
22
import * as React from 'react'
3-
import uuid from 'uuid'
3+
import uid from './uid'
44

55
import type { Props as ContentLoaderProps } from './index'
66

@@ -9,8 +9,8 @@ export type WrapProps = {
99
} & ContentLoaderProps
1010

1111
const Wrap = (props: WrapProps): React.Element<*> => {
12-
let idClip = uuid.v1()
13-
let idGradient = uuid.v1()
12+
let idClip = uid()
13+
let idGradient = uid()
1414

1515
return (
1616
<svg

src/uid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @flow
2+
export default (): string => Math.random().toString(36).substring(2)

0 commit comments

Comments
 (0)