Skip to content

Commit

Permalink
feat: create unscoped harlem package
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Dec 1, 2022
1 parent 248457d commit ac3e6e1
Show file tree
Hide file tree
Showing 87 changed files with 873 additions and 334 deletions.
9 changes: 5 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
"main": "src/index.ts",
"scripts": {
"start": "vite",
"serve": "vite preview",
"build": "vite build"
"build": "vite build",
"insights": "vite build --mode insights",
"serve": "vite build && vite preview"
},
"dependencies": {
"@harlem/core": "^2.4.0-beta.1",
"@harlem/extension-action": "^2.4.0-beta.1",
"@harlem/extension-compose": "^2.4.0-beta.1",
"@harlem/extension-history": "^2.4.0-beta.1",
"@harlem/extension-lazy": "^2.4.0-beta.1",
"@harlem/extension-storage": "^2.4.0-beta.1",
"@harlem/extension-trace": "^2.4.0-beta.1",
"@harlem/extension-transaction": "^2.4.0-beta.1",
"@harlem/plugin-devtools": "^2.4.0-beta.1",
"date-fns": "^2.29.3",
"date-fns-tz": "^1.3.7",
"flex-layout-attribute": "^1.0.3",
"harlem": "^2.4.0-beta.1",
"vue": "^3.2.45"
},
"devDependencies": {
"@vitejs/plugin-vue": "^3.2.0",
"@vue/compiler-sfc": "^3.2.45",
"rollup-plugin-visualizer": "^5.8.3",
"sass": "^1.56.1",
"vite": "^3.2.4"
}
Expand Down
10 changes: 2 additions & 8 deletions app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@ import App from './app.vue';

import {
createVuePlugin,
} from '@harlem/core';

import devtoolsPlugin from '@harlem/plugin-devtools';
} from 'harlem';

import {
createApp,
} from 'vue';

function start() {
return createApp(App)
.use(createVuePlugin({
plugins: [
devtoolsPlugin(),
],
}))
.use(createVuePlugin())
.mount('body');
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/stores/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import {
createStore,
} from '@harlem/core';
} from 'harlem';

export const {
state,
Expand Down
30 changes: 29 additions & 1 deletion app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import vuePlugin from '@vitejs/plugin-vue';

import {
defineConfig,
UserConfig,
} from 'vite';

export default defineConfig({
import {
visualizer,
} from 'rollup-plugin-visualizer';

const BASE_CONFIG: UserConfig = {
server: {
port: 6565,
},
Expand All @@ -24,4 +29,27 @@ export default defineConfig({
plugins: [
vuePlugin(),
],
};

export default defineConfig(({ mode }) => {
if (mode !== 'insights') {
return BASE_CONFIG;
}

return {
...BASE_CONFIG,
build: {
rollupOptions: {
plugins: [
visualizer({
filename: 'app.insights.html',
title: 'App Insights',
template: 'treemap',
open: true,
gzipSize: true,
}),
],
},
},
};
});
141 changes: 141 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import path from 'path';
import fse from 'fs-extra';

import {
build,
} from 'tsup';

import {
replace,
} from 'esbuild-plugin-replace';

/**
* @typedef Configuration
* @property {string} name
* @property {import('tsup').Options | (isProd: boolean) => import('tsup').Options} options
*/

/**
* @type import('tsup').Options
*/
const baseOptions = {
target: 'es2018',
sourcemap: false,
clean: false,
};

/**
* @type Configuration[]
*/
const configurations = [
{
name: 'commonjs',
options: isProd => ({
format: ['cjs'],
minify: isProd,
outExtension: () => ({
js: isProd ? '.cjs.prod.js' : '.cjs.js',
}),
esbuildPlugins: [
replace({
values: {
'__DEV__': isProd ? 'false' : 'process.env.NODE_ENV === "development"',
'__VUE_PROD_DEVTOOLS__': isProd ? 'false' : '(typeof __VUE_PROD_DEVTOOLS__ !== \'undefined\' && __VUE_PROD_DEVTOOLS__)',
},
}),
],
}),
},
{
name: 'esm-bundler',
options: {
format: ['esm'],
outExtension: () => ({
js: '.esm-bundler.js',
}),
esbuildPlugins: [
replace({
values: {
'__DEV__': 'process.env.NODE_ENV === "development"',
'__VUE_PROD_DEVTOOLS__': '(typeof __VUE_PROD_DEVTOOLS__ !== \'undefined\' && __VUE_PROD_DEVTOOLS__)',
},
}),
],
},
},
{
name: 'esm-browser',
options: isProd => ({
format: ['esm'],
minify: isProd,
outExtension: () => ({
js: isProd ? '.esm-browser.prod.js' : '.esm-browser.js',
}),
esbuildPlugins: [
replace({
values: {
'__DEV__': 'false',
'__VUE_PROD_DEVTOOLS__': 'false',
},
}),
],
}),
},
{
name: 'global',
options: isProd => ({
format: ['iife'],
minify: isProd,
outExtension: () => ({
js: isProd ? '.global.prod.js' : '.global.js',
}),
esbuildPlugins: [
replace({
values: {
'__DEV__': `${!isProd}`,
'__VUE_PROD_DEVTOOLS__': `${!isProd}`,
},
}),
],
}),
},
{
name: 'types',
options: {
dts: {
only: true,
},
},
},
];

/**
*
* @param {string} cwd
* @param {string} entry
* @param {import('tsup').Options} options
*/
export default async function(cwd, entry, options) {
const entryFile = path.resolve(cwd, entry);
const outDir = path.resolve(cwd, './dist');

await fse.emptyDir(outDir);

for (const { options: configuration } of configurations) {
const cfgOptions = typeof configuration === 'function'
? [configuration(false), configuration(true)]
: [configuration];

for (const configOptions of cfgOptions) {
await build({
...baseOptions,
...configOptions,
...options,
outDir,
entry: [
entryFile,
],
});
}
}
}
3 changes: 3 additions & 0 deletions core/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import build from '../build.mjs';

build(process.cwd(), './src/index.ts');
5 changes: 5 additions & 0 deletions core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (process.env.NODE_ENV === 'production') {
return require('./dist/index.cjs.prod.js');
} else {
return require('./dist/index.cjs.js');
}
1 change: 1 addition & 0 deletions core/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index.js';
30 changes: 19 additions & 11 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
"author": "Andrew Courtice <[email protected]>",
"description": "Powerfully simple global state management for Vue 3",
"homepage": "https://harlemjs.com",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "index.js",
"module": "dist/index.esm-bundler.js",
"types": "dist/index.d.ts",
"unpkg": "dist/index.global.js",
"jsdelivr": "dist/index.global.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": [
"dist",
"index.js",
"index.mjs"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
"import": {
"node": "./index.mjs",
"default": "./dist/index.esm-bundler.js"
},
"require": "./index.js",
"types": "./dist/index.d.ts"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"keywords": [
"vue",
Expand All @@ -34,8 +43,7 @@
"url": "https://github.com/andrewcourtice/harlem/issues"
},
"scripts": {
"dev": "yarn run --top-level tsup --watch src",
"build": "yarn run --top-level tsup",
"build": "node ./build.mjs",
"prepublishOnly": "yarn build"
},
"dependencies": {
Expand Down
10 changes: 0 additions & 10 deletions core/tsup.config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions extensions/action/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import build from '../../build.mjs';

build(process.cwd(), './src/index.ts');
5 changes: 5 additions & 0 deletions extensions/action/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (process.env.NODE_ENV === 'production') {
return require('./dist/index.cjs.prod.js');
} else {
return require('./dist/index.cjs.js');
}
1 change: 1 addition & 0 deletions extensions/action/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index.js';
30 changes: 19 additions & 11 deletions extensions/action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
"author": "Andrew Courtice <[email protected]>",
"description": "The official action extension for Harlem",
"homepage": "https://harlemjs.com",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "index.js",
"module": "dist/index.esm-bundler.js",
"types": "dist/index.d.ts",
"unpkg": "dist/index.global.js",
"jsdelivr": "dist/index.global.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": [
"dist",
"index.js",
"index.mjs"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
"import": {
"node": "./index.mjs",
"default": "./dist/index.esm-bundler.js"
},
"require": "./index.js",
"types": "./dist/index.d.ts"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"keywords": [
"vue",
Expand All @@ -36,8 +45,7 @@
"url": "https://github.com/andrewcourtice/harlem/issues"
},
"scripts": {
"dev": "yarn run --top-level tsup --watch src",
"build": "yarn run --top-level tsup",
"build": "node ./build.mjs",
"prepublishOnly": "yarn build"
},
"dependencies": {
Expand Down
Loading

0 comments on commit ac3e6e1

Please sign in to comment.