Flat bundles for each possible entry

This commit is contained in:
Mateusz Burzyński
2017-12-17 15:34:54 +01:00
committed by Maximilian Stoiber
parent 3a409ad090
commit 4b2045061e
10 changed files with 207 additions and 70 deletions

View File

@@ -1,13 +1,5 @@
{
"presets": [
["env", { "loose": true }],
"react"
],
"plugins": [
"flow-react-proptypes",
"add-module-exports",
"transform-flow-strip-types",
"transform-object-rest-spread",
"transform-class-properties"
"./.babelrc.js"
]
}

19
.babelrc.js Normal file
View File

@@ -0,0 +1,19 @@
const { NODE_ENV, UMD, PRODUCTION } = process.env
const test = NODE_ENV === 'test'
const modules = test ? 'commonjs' : false
const prod = !!PRODUCTION
module.exports = {
presets: [
['env', { loose: true, modules }],
'react'
],
plugins: [
!prod && 'flow-react-proptypes',
prod && 'transform-react-remove-prop-types',
!test && 'external-helpers',
'transform-flow-strip-types',
'transform-object-rest-spread',
'transform-class-properties',
].filter(Boolean)
}

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
node_modules
lib
npm-debug.log.*
dist
.DS_Store

View File

@@ -1,2 +1,2 @@
/* eslint-disable flowtype/require-valid-file-annotation */
module.exports = require('../lib/native')
module.exports = require('../dist/styled-components.native')

View File

@@ -1,2 +0,0 @@
/* eslint-disable */
module.exports = require('./lib/no-parser')

7
no-parser/package.json Normal file
View File

@@ -0,0 +1,7 @@
{
"name": "styled-components/no-parser",
"private": true,
"main": "../dist/styled-components-no-parser.cjs.js",
"module": "../dist/styled-components-no-parser.es.js",
"jsnext:main": "../dist/styled-components-no-parser.es.js"
}

View File

@@ -2,17 +2,22 @@
"name": "styled-components",
"version": "2.3.2",
"description": "Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅",
"main": "lib/index.js",
"main": "dist/styled-components.cjs.js",
"typings": "typings/styled-components.d.ts",
"jsnext:main": "dist/styled-components.es.js",
"module": "dist/styled-components.es.js",
"react-native": "dist/styled-components.native.js",
"scripts": {
"build": "npm run build:lib && npm run build:dist",
"prebuild:lib": "rimraf lib/*",
"build:lib": "babel --out-dir lib --ignore \"*.test.js\" src",
"prebuild:dist": "rimraf dist/*",
"build:dist": "rollup -c && rollup -c --environment ESBUNDLE && rollup -c --environment PRODUCTION",
"build:watch": "npm run build:lib -- --watch",
"build": "run-p build:**",
"prebuild": "rimraf dist",
"build:es": "cross-env ESBUNDLE=true rollup -c",
"build:cjs": "cross-env BABEL_ENV=cjs CJSBUNDLE=true rollup -c",
"build:umd:prod": "cross-env UMD=true PRODUCTION=true rollup -c",
"build:umd:dev": "cross-env UMD=true rollup -c",
"build:native": "cross-env BABEL_ENV=cjs NATIVEBUNDLE=true rollup -c",
"build:primitives": "cross-env BABEL_ENV=cjs PRIMITIVESBUNDLE=true rollup -c",
"build:no-parser:es": "cross-env NOPARSERBUNDLE=true rollup -c",
"build:no-parser:cjs": "cross-env BABEL_ENV=cjs NOPARSERBUNDLE=true rollup -c",
"test": "npm run test:web && npm run test:native && npm run test:size",
"test:web": "jest --outputFile test-results.json --json",
"test:web:watch": "npm run test:web -- --watch",
@@ -36,7 +41,7 @@
"url": "git+https://github.com/styled-components/styled-components.git"
},
"files": [
"no-parser.js",
"no-parser",
"CONTRIBUTING.md",
"CODE_OF_CONDUCT.md",
"dist",
@@ -88,6 +93,7 @@
"babel-preset-react": "^6.22.0",
"bundlesize": "^0.13.2",
"chokidar": "^1.6.0",
"cross-env": "^5.1.1",
"danger": "^2.0.0",
"danger-plugin-jest": "^1.1.0",
"enzyme": "^2.8.2",
@@ -108,6 +114,7 @@
"jsdom": "^9.10.0",
"lint-staged": "^6.0.0",
"node-watch": "^0.4.1",
"npm-run-all": "^4.1.2",
"pre-commit": "^1.2.2",
"prettier": "1.9.2",
"puppeteer": "^0.13.0",
@@ -117,7 +124,7 @@
"react-primitives": "^0.4.2",
"react-test-renderer": "^15.6.1",
"rimraf": "^2.6.1",
"rollup": "0.43.0",
"rollup": "^0.52.2",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^6.0.0",
"rollup-plugin-flow": "^1.1.1",

View File

@@ -1,2 +1,2 @@
/* eslint-disable flowtype/require-valid-file-annotation */
module.exports = require('../lib/primitives')
module.exports = require('../dist/styled-components.primitives')

View File

@@ -12,20 +12,59 @@ import pkg from './package.json'
const processShim = '\0process-shim'
const prod = process.env.PRODUCTION
const esbundle = process.env.ESBUNDLE
const {
PRODUCTION,
UMD,
BABEL_ENV,
ESBUNDLE,
CJSBUNDLE,
NATIVEBUNDLE,
PRIMITIVESBUNDLE,
NOPARSERBUNDLE,
} = process.env
let targets
if (prod) {
let input
let output
if (UMD && PRODUCTION) {
console.log('Creating production UMD bundle...')
targets = [{ dest: 'dist/styled-components.min.js', format: 'umd' }]
} else if (esbundle) {
console.log('Creating ES modules bundle...')
targets = [{ dest: 'dist/styled-components.es.js', format: 'es' }]
} else {
input = 'src/index.js'
output = [
{ file: 'dist/styled-components.min.js', format: 'umd', name: 'styled' },
]
} else if (UMD) {
console.log('Creating development UMD bundle')
targets = [{ dest: 'dist/styled-components.js', format: 'umd' }]
input = 'src/index.js'
output = [
{ file: 'dist/styled-components.js', format: 'umd', name: 'styled' },
]
} else if (ESBUNDLE) {
console.log('Creating ES modules bundle...')
input = 'src/index.js'
output = [{ file: 'dist/styled-components.es.js', format: 'es' }]
} else if (CJSBUNDLE) {
console.log('Creating CJS modules bundle...')
input = 'src/index.js'
output = [{ file: 'dist/styled-components.cjs.js', format: 'cjs' }]
} else if (NATIVEBUNDLE) {
console.log('Creating React Native bundle...')
input = 'src/native/index.js'
output = [{ file: 'dist/styled-components.native.js', format: 'cjs' }]
} else if (PRIMITIVESBUNDLE) {
console.log('Creating React Primitives bundle...')
input = 'src/primitives/index.js'
output = [{ file: 'dist/styled-components.primitives.js', format: 'cjs' }]
} else if (NOPARSERBUNDLE && BABEL_ENV === 'cjs') {
console.log('Creating CJS no parser bundle...')
input = 'src/no-parser/index.js'
output = [{ file: 'dist/styled-components-no-parser.cjs.js', format: 'cjs' }]
} else if (NOPARSERBUNDLE) {
console.log('Creating ES no parser bundle...')
input = 'src/no-parser/index.js'
output = [{ file: 'dist/styled-components-no-parser.es.js', format: 'es' }]
} else {
throw new Error('Unknown bundle type.')
}
output[0].exports = 'named'
const plugins = [
// Unlike Webpack and Browserify, Rollup doesn't automatically shim Node
@@ -47,37 +86,30 @@ const plugins = [
commonjs({
ignoreGlobal: true,
}),
!esbundle && replace({
'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
}),
prod && inject({
process: processShim,
}),
babel({
babelrc: false,
presets: [
['env', { modules: false, loose: true }],
'react',
],
plugins: [
!prod && 'flow-react-proptypes',
prod && 'transform-react-remove-prop-types',
'transform-flow-strip-types',
'external-helpers',
'transform-object-rest-spread',
'transform-class-properties',
].filter(Boolean),
}),
UMD &&
replace({
'process.env.NODE_ENV': JSON.stringify(
PRODUCTION ? 'production' : 'development',
),
}),
PRODUCTION &&
inject({
process: processShim,
}),
babel(),
].filter(Boolean)
if (prod) plugins.push(uglify(), visualizer({ filename: './bundle-stats.html' }))
if (PRODUCTION) {
plugins.push(uglify(), visualizer({ filename: './bundle-stats.html' }))
}
export default {
entry: 'src/index.js',
moduleName: 'styled',
external: ['react'].concat(esbundle ? Object.keys(pkg.dependencies) : []),
exports: 'named',
targets,
input,
external: ['react', 'react-native', 'react-primitives'].concat(
!UMD ? Object.keys(pkg.dependencies) : [],
),
output,
plugins,
globals: { react: 'React' },
outro: BABEL_ENV === 'cjs' ? "module.exports = exports['default']" : '',
}

103
yarn.lock
View File

@@ -1915,6 +1915,13 @@ create-react-class@^15.5.3:
loose-envify "^1.3.1"
object-assign "^4.1.1"
cross-env@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.1.tgz#b6d8ab97f304c0f71dae7277b75fe424c08dfa74"
dependencies:
cross-spawn "^5.1.0"
is-windows "^1.0.0"
cross-spawn-async@^2.1.1:
version "2.2.5"
resolved "https://registry.yarnpkg.com/cross-spawn-async/-/cross-spawn-async-2.2.5.tgz#845ff0c0834a3ded9d160daca6d390906bb288cc"
@@ -1929,7 +1936,7 @@ cross-spawn@^3.0.1:
lru-cache "^4.0.1"
which "^1.2.9"
cross-spawn@^5.0.1:
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
dependencies:
@@ -2411,6 +2418,16 @@ errorhandler@~1.4.2:
accepts "~1.3.0"
escape-html "~1.0.3"
es-abstract@^1.4.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864"
dependencies:
es-to-primitive "^1.1.1"
function-bind "^1.1.1"
has "^1.0.1"
is-callable "^1.1.3"
is-regex "^1.0.4"
es-abstract@^1.6.1, es-abstract@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.7.0.tgz#dfade774e01bfcd97f96180298c449c8623fb94c"
@@ -3178,6 +3195,10 @@ function-bind@^1.0.2, function-bind@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771"
function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
function.prototype.name@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.0.0.tgz#5f523ca64e491a5f95aba80cc1e391080a14482e"
@@ -3897,7 +3918,7 @@ is-redirect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24"
is-regex@^1.0.3:
is-regex@^1.0.3, is-regex@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
dependencies:
@@ -3953,6 +3974,10 @@ is-windows@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-0.2.0.tgz#de1aa6d63ea29dd248737b69f1ff8b8002d2108c"
is-windows@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9"
is-wsl@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
@@ -4382,6 +4407,10 @@ jsome@^2.3.25:
json-stringify-safe "^5.0.1"
yargs "^4.8.0"
json-parse-better-errors@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.1.tgz#50183cd1b2d25275de069e9e71b467ac9eab973a"
json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
@@ -4578,6 +4607,15 @@ load-json-file@^2.0.0:
pify "^2.0.0"
strip-bom "^3.0.0"
load-json-file@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
dependencies:
graceful-fs "^4.1.2"
parse-json "^4.0.0"
pify "^3.0.0"
strip-bom "^3.0.0"
locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@@ -4900,6 +4938,10 @@ memory-fs@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290"
memorystream@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
merge-descriptors@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
@@ -5275,6 +5317,20 @@ npm-path@^2.0.2:
dependencies:
which "^1.2.10"
npm-run-all@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.2.tgz#90d62d078792d20669139e718621186656cea056"
dependencies:
ansi-styles "^3.2.0"
chalk "^2.1.0"
cross-spawn "^5.1.0"
memorystream "^0.3.1"
minimatch "^3.0.4"
ps-tree "^1.1.0"
read-pkg "^3.0.0"
shell-quote "^1.6.1"
string.prototype.padend "^3.0.0"
npm-run-path@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-1.0.0.tgz#f5c32bf595fe81ae927daec52e82f8b000ac3c8f"
@@ -5558,6 +5614,13 @@ parse-json@^3.0.0:
dependencies:
error-ex "^1.3.1"
parse-json@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
dependencies:
error-ex "^1.3.1"
json-parse-better-errors "^1.0.1"
parse-link-header@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parse-link-header/-/parse-link-header-1.0.1.tgz#bedfe0d2118aeb84be75e7b025419ec8a61140a7"
@@ -5624,6 +5687,12 @@ path-type@^1.0.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"
path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
dependencies:
pify "^3.0.0"
pause-stream@0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445"
@@ -5823,7 +5892,7 @@ prr@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a"
ps-tree@^1.0.1:
ps-tree@^1.0.1, ps-tree@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.1.0.tgz#b421b24140d6203f1ed3c76996b4427b08e8c014"
dependencies:
@@ -6145,6 +6214,14 @@ read-pkg@^2.0.0:
normalize-package-data "^2.3.2"
path-type "^2.0.0"
read-pkg@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
dependencies:
load-json-file "^4.0.0"
normalize-package-data "^2.3.2"
path-type "^3.0.0"
readable-stream@^2.0.0, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2:
version "2.2.9"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8"
@@ -6475,11 +6552,9 @@ rollup-pluginutils@^1.2.0, rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.1,
estree-walker "^0.2.1"
minimatch "^3.0.2"
rollup@0.43.0:
version "0.43.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.43.0.tgz#b36bdb75fa5e0823b6de8aee18ff7b5655520543"
dependencies:
source-map-support "^0.4.0"
rollup@^0.52.2:
version "0.52.2"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.52.2.tgz#d75bc6f37be02fd27cbb344e57e77b30042bd2cf"
run-async@^0.1.0:
version "0.1.0"
@@ -6703,7 +6778,7 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
shell-quote@1.6.1:
shell-quote@1.6.1, shell-quote@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"
dependencies:
@@ -6754,7 +6829,7 @@ sntp@1.x.x:
dependencies:
hoek "2.x.x"
source-map-support@^0.4.0, source-map-support@^0.4.2:
source-map-support@^0.4.2:
version "0.4.14"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.14.tgz#9d4463772598b86271b4f523f6c1f4e02a7d6aef"
dependencies:
@@ -6920,6 +6995,14 @@ string-width@^2.0.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^3.0.0"
string.prototype.padend@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0"
dependencies:
define-properties "^1.1.2"
es-abstract "^1.4.3"
function-bind "^1.0.2"
string_decoder@^0.10.25, string_decoder@~0.10.x:
version "0.10.31"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"