Skip to content
Permalink
Browse files

build: fix module bundle (#196)

  • Loading branch information...
miralemd committed Sep 23, 2018
1 parent 26f3da9 commit 0834954f197cf2ea9531997513b601faa82e61b3
Showing with 201 additions and 868 deletions.
  1. +5 −3 package.json
  2. +5 −10 packages/picasso.js/package.json
  3. +3 −4 plugins/hammer/package.json
  4. +3 −3 plugins/q/package.json
  5. +78 −0 rollup.config.js
  6. +0 −57 webpack.config.js
  7. +107 −791 yarn.lock
@@ -7,7 +7,6 @@
},
"scripts": {
"build": "cross-env NODE_ENV=production lerna run build --concurrency 99",
"build:dev": "lerna run build --concurrency 99",
"build:watch": "lerna run build:watch --stream --no-sort --concurrency 99",
"build:website": "cd website && yarn install && yarn run build",
"bump": "lerna publish --no-push",
@@ -46,8 +45,11 @@
"lerna": "^3.1.1",
"mocha-junit-reporter": "^1.18.0",
"protractor": "^5.4.0",
"webpack": "^4.17.0",
"webpack-cli": "^3.1.0"
"rollup": "^0.66.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-uglify": "^6.0.0"
},
"workspaces": [
"docs",
@@ -24,20 +24,18 @@
"/src"
],
"main": "dist/picasso.js",
"module": "src/index.js",
"source": true,
"module": "dist/picasso.esm.js",
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config ../../webpack.config.js",
"build:dev": "webpack --config ../../webpack.config.js",
"build:watch": "npm run build:dev -- -w",
"build": "cross-env NODE_ENV=production rollup --config ../../rollup.config.js",
"build:watch": "yarn run build -w",
"lint": "eslint src test",
"lint:fix": "npm run lint -- --fix",
"test:integration:local": "webdriver-manager update --versions.chrome 2.37 --gecko false && aw protractor -c aw.config.js --require @babel/register --require @babel/helpers",
"fixture:server": "aw serve -c aw.webserver.config.js",
"version": "node scripts/version.js && git add src/about.js",
"prepublishOnly": "rm -rf dist && npm run build"
},
"dependencies": {
"devDependencies": {
"d3-ease": "^1.0.3",
"d3-format": "^1.3.0",
"d3-hierarchy": "^1.1.6",
@@ -49,10 +47,7 @@
"hammerjs": "^2.0.8",
"node-event-emitter": "0.0.1",
"path2d-polyfill": "0.2.1",
"preact": "^8.3.0"
},
"devDependencies": {
"rimraf": "^2.6.2",
"preact": "^8.3.0",
"test-utils": "^0.13.1"
}
}
@@ -12,11 +12,10 @@
"/dist"
],
"main": "dist/picasso-hammer.js",
"module": "src/index.js",
"module": "dist/picasso-hammer.esm.js",
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config ../../webpack.config.js",
"build:dev": "webpack --config ../../webpack.config.js",
"build:watch": "npm run build:dev -- -w",
"build": "cross-env NODE_ENV=production rollup --config ../../rollup.config.js",
"build:watch": "yarn run build -w",
"lint": "eslint src test",
"prepublishOnly": "rm -rf dist && npm run build"
},
@@ -12,10 +12,10 @@
"/dist"
],
"main": "dist/picasso-q.js",
"module": "dist/picasso-q.esm.js",
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config ../../webpack.config.js",
"build:dev": "webpack --config ../../webpack.config.js",
"build:watch": "npm run build:dev -- -w",
"build": "cross-env NODE_ENV=production rollup --config ../../rollup.config.js",
"build:watch": "yarn run build -w",
"lint": "eslint src test",
"prepublishOnly": "rm -rf dist && npm run build"
},
@@ -0,0 +1,78 @@
const path = require('path');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const { uglify } = require('rollup-plugin-uglify');
const jsxPlugin = require('@babel/plugin-transform-react-jsx');

const cwd = process.cwd();
const pkg = require(path.join(cwd, 'package.json')); // eslint-disable-line
const {
name,
version
} = pkg;

const banner = `/*
* ${name} v${version}
* Copyright (c) ${new Date().getFullYear()} QlikTech International AB
* Released under the MIT license.
*/
`;

const watch = process.argv.indexOf('-w') > 2;

const config = (isEsm) => {
const outputFile = isEsm ? pkg.module : pkg.main;
const basename = path.basename(outputFile);
const dir = path.dirname(outputFile);
const umdName = basename.replace(/-([a-z])/g, (m, p1) => p1.toUpperCase()).split('.js').join('');

const cfg = {
input: path.resolve(cwd, 'src', 'index'),
output: {
file: path.resolve(dir, basename),
format: isEsm ? 'es' : 'umd',
exports: 'default',
name: umdName,
sourcemap: true,
banner
},
plugins: [
nodeResolve(),
babel({
include: [
'src/**',
/path2d-polyfill/
],
presets: [
['@babel/preset-env', {
modules: false,
targets: {
browsers: ['ie 11']
}
}]
],
plugins: [
[jsxPlugin, { pragma: 'h' }]
]
}),
commonjs()
]
};

if (process.env.NODE_ENV === 'production' && !isEsm) {
cfg.plugins.push(uglify({
output: {
preamble: banner
}
}));
}

return cfg;
};

module.exports = [
watch ? false : config(),
config(true)
].filter(Boolean);

This file was deleted.

0 comments on commit 0834954

Please sign in to comment.
You can’t perform that action at this time.