From 863a8030005eeb4c8e4b6054e908be4c98eb808a Mon Sep 17 00:00:00 2001 From: Eugene Rwagasore <1290048+erwagasore@users.noreply.github.com> Date: Sat, 11 Jul 2020 17:37:37 +0200 Subject: [PATCH] fix: Switch to rollup for library bundling (#49) * Forced the bundle to use commonjs2 * fix: Configured the publish to allow import without the extension * fix: updated webpack config to solve issue with jest tests * fix: switched from webpack to using rollup for bundling --- packages/blocjs/package.json | 25 +++++++++--------- packages/blocjs/rollup.config.js | 45 ++++++++++++++++++++++++++++++++ packages/blocjs/src/index.js | 2 +- 3 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 packages/blocjs/rollup.config.js diff --git a/packages/blocjs/package.json b/packages/blocjs/package.json index 08ab48a..eaa1300 100644 --- a/packages/blocjs/package.json +++ b/packages/blocjs/package.json @@ -4,13 +4,10 @@ "description": "Blocjs is a minimal structural set of components built with Styled System", "author": "Team Pindo ", "license": "MIT", - "main": "src/index.js", - "files": [ - "dist" - ], + "main": "dist/index.js", + "files": ["/dist"], "scripts": { - "develop": "webpack --mode development --watch", - "build": "webpack --mode production" + "build": "rollup -c" }, "dependencies": { "@styled-system/css": "^5.1.5", @@ -19,18 +16,20 @@ "devDependencies": { "@babel/core": "^7.10.2", "@babel/preset-env": "^7.10.2", - "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "babel-loader": "^8.1.0", - "webpack": "^4.43.0", - "webpack-cli": "^3.3.12", - "webpack-node-externals": "^1.7.2", + "@babel/preset-react": "^7.8.0", + "rollup": "^1.27.8", + "rollup-plugin-babel": "^4.3.3", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-peer-deps-external": "^2.2.0", + "rollup-plugin-terser": "^5.1.2", + "rollup-plugin-uglify": "^6.0.3", "styled-components": "^5.1.1" }, "peerDependencies": { - "react": "^16.13.1", "styled-components": "^5.1.1" }, - "repository": { + "repository": { "type": "git", "url": "git+https://github.com/pindoio/blocjs.git" } diff --git a/packages/blocjs/rollup.config.js b/packages/blocjs/rollup.config.js new file mode 100644 index 0000000..f2259d7 --- /dev/null +++ b/packages/blocjs/rollup.config.js @@ -0,0 +1,45 @@ +import babel from "rollup-plugin-babel"; +import commonjs from "rollup-plugin-commonjs"; +import resolve from "rollup-plugin-node-resolve"; +import external from "rollup-plugin-peer-deps-external"; +import { terser } from "rollup-plugin-terser"; + +import packageJSON from "./package.json"; +const input = "./src/index.js"; +const minifyExtension = pathToFile => pathToFile.replace(/\.js$/, ".min.js"); + +export default [ + // CommonJS + { + input, + output: { + file: packageJSON.main, + format: "cjs" + }, + + plugins: [ + babel({ + exclude: "node_modules/**" + }), + external(), + resolve(), + commonjs() + ] + }, + { + input, + output: { + file: minifyExtension(packageJSON.main), + format: "cjs" + }, + plugins: [ + babel({ + exclude: "node_modules/**" + }), + external(), + resolve(), + commonjs(), + terser() + ] + } +]; diff --git a/packages/blocjs/src/index.js b/packages/blocjs/src/index.js index 4cec17a..659f0f9 100644 --- a/packages/blocjs/src/index.js +++ b/packages/blocjs/src/index.js @@ -1,3 +1,3 @@ export { default as Box } from "./box"; -export { default as Bloc } from "./bloc"; export { default as Flex } from "./flex"; +export { default as Bloc } from "./bloc";