diff --git a/packages/component/.size-snapshot.json b/packages/component/.size-snapshot.json index 03abd0daf..2f50e41a1 100644 --- a/packages/component/.size-snapshot.json +++ b/packages/component/.size-snapshot.json @@ -1,10 +1,10 @@ { - "dist/loadable.cjs.js": { + "dist/cjs/loadable.cjs.js": { "bundled": 16900, "minified": 7226, "gzipped": 2553 }, - "dist/loadable.esm.mjs": { + "dist/esm/loadable.esm.mjs": { "bundled": 16517, "minified": 6917, "gzipped": 2490, diff --git a/packages/component/package.json b/packages/component/package.json index 0a9c0267e..ae3cd9f7a 100644 --- a/packages/component/package.json +++ b/packages/component/package.json @@ -2,13 +2,13 @@ "name": "@loadable/component", "description": "React code splitting made easy.", "version": "5.16.3", - "main": "./dist/loadable.cjs.js", - "module": "./dist/loadable.esm.mjs", + "main": "./dist/cjs/loadable.cjs.js", + "module": "./dist/esm/loadable.esm.mjs", "exports": { ".": { - "require": "./dist/loadable.cjs.js", - "import": "./dist/loadable.esm.mjs", - "default": "./dist/loadable.cjs.js" + "require": "./dist/cjs/loadable.cjs.js", + "import": "./dist/esm/loadable.esm.mjs", + "default": "./dist/cjs/loadable.cjs.js" } }, "repository": "git@github.com:gregberge/loadable-components.git", @@ -37,7 +37,8 @@ "license": "MIT", "scripts": { "prebuild": "shx rm -rf dist", - "build": "cross-env rollup -c", + "build": "cross-env rollup -c && yarn create-cjs-package-json", + "create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", "prepublishOnly": "yarn run build" }, "peerDependencies": { diff --git a/packages/server/.eslintrc.json b/packages/server/.eslintrc.json deleted file mode 100644 index d88e23630..000000000 --- a/packages/server/.eslintrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "import/extensions": ["error", "always", { "ignorePackages": true }] - } -} diff --git a/packages/server/.size-snapshot.json b/packages/server/.size-snapshot.json new file mode 100644 index 000000000..ddee65254 --- /dev/null +++ b/packages/server/.size-snapshot.json @@ -0,0 +1,21 @@ +{ + "dist/cjs/loadable-server.cjs.js": { + "bundled": 18664, + "minified": 10144, + "gzipped": 2837 + }, + "dist/esm/loadable-server.esm.mjs": { + "bundled": 18299, + "minified": 9859, + "gzipped": 2766, + "treeshaked": { + "rollup": { + "code": 279, + "import_statements": 235 + }, + "webpack": { + "code": 13218 + } + } + } +} diff --git a/packages/server/package.json b/packages/server/package.json index 6e18fc195..6b53a140c 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -3,13 +3,13 @@ "description": "Server utilities for loadable.", "version": "5.16.2", "type": "module", - "main": "./lib/cjs/index.js", - "module": "./lib/esm/index.js", + "main": "./dist/cjs/loadable-server.cjs.js", + "module": "./dist/esm/loadable-server.esm.mjs", "exports": { ".": { - "require": "./lib/cjs/index.js", - "import": "./lib/esm/index.js", - "default": "./lib/cjs/index.js" + "require": "./dist/cjs/loadable-server.cjs.js", + "import": "./dist/esm/loadable-server.esm.mjs", + "default": "./dist/cjs/loadable-server.cjs.js" } }, "repository": "git@github.com:gregberge/loadable-components.git", @@ -29,12 +29,9 @@ }, "license": "MIT", "scripts": { - "prebuild": "shx rm -rf lib", - "build:esm": "MODULE_TARGET=esm yarn run build:script -d lib/esm", - "build:cjs": "MODULE_TARGET=cjs yarn run build:script -d lib/cjs && yarn run create-cjs-package-json", - "build:script": "BUILD_TARGET=node babel --config-file ../../babel.config.js --ignore \"**/*.test.js\" src", - "build": "yarn build:esm && yarn build:cjs", - "create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json", + "prebuild": "shx rm -rf dist", + "build": "cross-env rollup -c && yarn create-cjs-package-json", + "create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", "prepublishOnly": "yarn run build", "update-fixtures": "yarn --cwd ../../examples/__fixtures__ build:webpack && rm -rf ./__fixtures__ && cp -R ../../examples/__fixtures__/target ./__fixtures__ " }, diff --git a/packages/server/rollup.config.js b/packages/server/rollup.config.js new file mode 100644 index 000000000..6b937fcc5 --- /dev/null +++ b/packages/server/rollup.config.js @@ -0,0 +1,48 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import nodeResolve from 'rollup-plugin-node-resolve' +import babel from 'rollup-plugin-babel' +import replace from 'rollup-plugin-replace' +import commonjs from 'rollup-plugin-commonjs' +import { terser } from 'rollup-plugin-terser' +import { sizeSnapshot } from 'rollup-plugin-size-snapshot' +import pkg from './package.json' + +const input = 'src/index.js' +const name = 'loadable' +const globals = { + react: 'React', + 'hoist-non-react-statics': 'hoistNonReactStatics', +} + +const external = id => !id.startsWith('.') && !id.startsWith('/') + +const getBabelOptions = ({ useESModules }) => ({ + exclude: '**/node_modules/**', + runtimeHelpers: true, + presets: [ + ['@babel/preset-env', { loose: true }], + ['@babel/preset-react', { useBuiltIns: true }], + ], + plugins: [ + '@babel/plugin-proposal-class-properties', + 'babel-plugin-annotate-pure-calls', + ['@babel/plugin-transform-runtime', { useESModules }], + ], +}) + +export default [ + // cjs + { + input, + output: { file: pkg.main, format: 'cjs', exports: 'named' }, + external, + plugins: [babel(getBabelOptions({ useESModules: false })), sizeSnapshot()], + }, + // esm + { + input, + output: { file: pkg.module, format: 'esm' }, + external, + plugins: [babel(getBabelOptions({ useESModules: true })), sizeSnapshot()], + }, +] diff --git a/packages/server/src/ChunkExtractor.js b/packages/server/src/ChunkExtractor.js index 80e95f2b6..584ab5083 100644 --- a/packages/server/src/ChunkExtractor.js +++ b/packages/server/src/ChunkExtractor.js @@ -1,13 +1,13 @@ /* eslint-disable react/no-danger */ import path from 'path' import fs from 'fs' -import uniq from 'lodash/uniq.js' -import uniqBy from 'lodash/uniqBy.js' -import flatMap from 'lodash/flatMap.js' +import uniq from 'lodash/uniq' +import uniqBy from 'lodash/uniqBy' +import flatMap from 'lodash/flatMap' import React from 'react' -import { invariant, getRequiredChunkKey } from './sharedInternals.js' -import ChunkExtractorManager from './ChunkExtractorManager.js' -import { smartRequire, joinURLPath, readJsonFileSync } from './util.js' +import { invariant, getRequiredChunkKey } from './sharedInternals' +import ChunkExtractorManager from './ChunkExtractorManager' +import { smartRequire, joinURLPath, readJsonFileSync } from './util' const EXTENSION_SCRIPT_TYPES = { '.js': 'script', diff --git a/packages/server/src/ChunkExtractor.test.js b/packages/server/src/ChunkExtractor.test.js index 9f05daa2d..310782697 100644 --- a/packages/server/src/ChunkExtractor.test.js +++ b/packages/server/src/ChunkExtractor.test.js @@ -1,8 +1,8 @@ /* eslint-disable import/no-extraneous-dependencies */ -import 'regenerator-runtime/runtime.js' +import 'regenerator-runtime/runtime' import path from 'path' import stats from '../__fixtures__/stats.json' -import ChunkExtractor from './ChunkExtractor.js' +import ChunkExtractor from './ChunkExtractor' const targetPath = path.resolve( __dirname, diff --git a/packages/server/src/ChunkExtractorManager.js b/packages/server/src/ChunkExtractorManager.js index 4456f6b0c..899464615 100644 --- a/packages/server/src/ChunkExtractorManager.js +++ b/packages/server/src/ChunkExtractorManager.js @@ -1,5 +1,5 @@ import React from 'react' -import { Context } from './sharedInternals.js' +import { Context } from './sharedInternals' const ChunkExtractorManager = ({ extractor, children }) => ( {children} diff --git a/packages/server/src/index.js b/packages/server/src/index.js index b26509c78..2e96c1aca 100644 --- a/packages/server/src/index.js +++ b/packages/server/src/index.js @@ -1,2 +1,2 @@ -export { default as ChunkExtractorManager } from './ChunkExtractorManager.js' -export { default as ChunkExtractor } from './ChunkExtractor.js' +export { default as ChunkExtractorManager } from './ChunkExtractorManager' +export { default as ChunkExtractor } from './ChunkExtractor' diff --git a/packages/server/src/util.test.js b/packages/server/src/util.test.js index 63f87d7d4..81b1aaad9 100644 --- a/packages/server/src/util.test.js +++ b/packages/server/src/util.test.js @@ -1,4 +1,4 @@ -import { joinURLPath } from './util.js' +import { joinURLPath } from './util' describe('util', () => { describe('#joinURLPath', () => {