Skip to content

Commit

Permalink
Convert build to rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
tsov committed Sep 25, 2023
1 parent 16c3172 commit d7a4feb
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 1,053 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-cycles-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/draggable': minor
---

Converted build from webpack to rollout. Import paths have changed
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: Library typecheck
run: yarn type-check

- name: Scripts typecheck
run: yarn type-check:scripts
- name: Build
run: yarn build

- name: Test
run: yarn test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ example.html

coverage/
docs/
lib/
coverage/
build/
.rollup.cache/

# 'cause we are all yarny and stuff
package-lock.json
47 changes: 47 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @type {import('@babel/core').TransformOptions}
*/
module.exports = function (api) {
api.cache(true);

return {
presets: [
[
'@babel/preset-env',
{useBuiltIns: 'entry', corejs: '3.0', bugfixes: true},
],
['@babel/preset-typescript'],
],
assumptions: {
setPublicClassFields: true,
privateFieldsAsProperties: true,
// nothing accesses `document.all`:
noDocumentAll: true,
// nothing relies on class constructors invoked without `new` throwing:
noClassCalls: true,
// nothing should be relying on tagged template strings being frozen:
mutableTemplateObject: true,
// nothing is relying on Function.prototype.length:
ignoreFunctionLength: true,
// nothing is relying on mutable re-exported bindings:
constantReexports: true,
// don't bother marking Module records non-enumerable:
enumerableModuleMeta: true,
// nothing uses [[Symbol.toPrimitive]]:
// (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
ignoreToPrimitiveHint: true,
// nothing relies on spread copying Symbol keys: ({...{ [Symbol()]: 1 }})
objectRestNoSymbols: true,
// nothing relies on `new (() => {})` throwing:
noNewArrows: true,
// transpile object spread to assignment instead of defineProperty():
setSpreadProperties: true,
// nothing should be using custom iterator protocol:
skipForOfIteratorClosing: true,
// nothing inherits from a constructor function with explicit return value:
superIsCallableConstructor: true,
// nothing relies on CJS-transpiled namespace imports having all properties prior to module execution completing:
noIncompleteNsImportDetection: true,
},
};
};
9 changes: 9 additions & 0 deletions config/typescript/rollup-plugin-includepaths.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module 'rollup-plugin-includepaths' {
interface Options {
include: {[key: string]: string};
paths: string[];
extensions: string[];
}
export = includePaths;
function includePaths(object: Options);
}
49 changes: 30 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,49 @@
"drag-and-drop",
"es6"
],
"main": "./lib/draggable.bundle.js",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.esnext",
"umd": "build/umd/index.js",
"types": "./index.d.ts",
"scripts": {
"start": "concurrently \"yarn watch\" \"cd examples && yarn && yarn start\"",
"build": "yarn build:production",
"watch": "ts-node --project='./scripts/tsconfig.json' ./scripts/watch.ts",
"watch": "yarn build:development --watch",
"release": "yarn run build:production && changeset publish",
"lint": "eslint ./src ./scripts ./test --max-warnings 0",
"type-check": "tsc --noEmit",
"type-check:scripts": "tsc --noEmit --project scripts",
"lint": "eslint ./src ./test --max-warnings 0",
"type-check": "tsc -b",
"esdoc": "esdoc -c esdoc.json",
"test": "jest",
"test-ci": "jest --coverage && codecov",
"build:development": "ts-node --project='./scripts/tsconfig.json' ./scripts/build.ts",
"build:production": "ts-node --project='./scripts/tsconfig.json' ./scripts/build.ts --production",
"verify": "yarn lint && yarn type-check && yarn type-check:scripts && yarn build && yarn test"
"build:development": "yarn rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
"build:production": "tsc && yarn rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
"verify": "yarn lint && yarn type-check && yarn build && yarn test"
},
"files": [
"lib/**/*.js",
"build/**/*",
"index.d.ts"
],
"devDependencies": {
"@babel/core": "^7.22.20",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@microsoft/tsdoc": "^0.14.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.4",
"@shopify/babel-preset": "^25.0.0",
"@shopify/eslint-plugin": "^43.0.0",
"@shopify/prettier-config": "^1.1.2",
"@shopify/typescript-configs": "^5.1.0",
"@types/jest": "^29.5.5",
"@types/node": "^20.6.3",
"@types/webpack": "^5.28.2",
"@types/webpack-bundle-analyzer": "^4.6.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"babel-preset-shopify": "^21.0.0",
"codecov": "^3.0.2",
"concurrently": "^3.5.1",
"core-js": "^3.32.2",
"esdoc": "^1.1.0",
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0",
Expand All @@ -70,17 +73,25 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^3.0.3",
"rollup": "^3.29.3",
"rollup-plugin-includepaths": "^0.2.4",
"rollup-plugin-node-externals": "^6.1.1",
"timers": "^0.1.1",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"webpack": "^5.88.2",
"webpack-bundle-analyzer": "^4.9.1",
"webpack-cli": "^5.1.4"
"typescript": "^5.2.2"
},
"publishConfig": {
"access": "public",
"@shopify:registry": "https://registry.npmjs.org"
}
},
"browserslist": [
"last 3 chrome versions",
"last 3 firefox versions",
"last 3 opera versions",
"last 3 edge versions",
"last 3 safari versions",
"last 3 chromeandroid versions",
"last 1 firefoxandroid versions",
"ios >= 13.4"
]
}
86 changes: 86 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {readFileSync} from 'fs';
import * as path from 'path';

import {RollupOptions} from 'rollup';
import {babel, RollupBabelInputPluginOptions} from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import includePaths from 'rollup-plugin-includepaths';

const packageJSON = readFileSync(
new URL('./package.json', import.meta.url).pathname,
) as unknown;

const pkg = JSON.parse(packageJSON as string);
const extensions = ['.js', '.jsx', '.ts', '.tsx'];

function generateConfig({
output,
targets,
}: {
output: RollupOptions['output'];
targets: RollupBabelInputPluginOptions['targets'];
}): RollupOptions {
return {
input: './src/index',
plugins: [
includePaths({
include: {
shared: 'src/shared',
},
paths: ['src/'],
extensions: ['.js', '.ts'],
}),
nodeResolve({extensions}),
commonjs(),
babel({
extensions,
exclude: 'node_modules/**',
babelHelpers: 'bundled',
envName: 'production',
targets,
}),
],
output,
};
}

const config = [
generateConfig({
targets: [...pkg.browserslist],
output: [
{
format: 'cjs',
dir: path.dirname(pkg.main),
preserveModules: true,
entryFileNames: '[name].js',
exports: 'named',
},
{
format: 'esm',
dir: path.dirname(pkg.module),
preserveModules: true,
entryFileNames: '[name].js',
},
{
format: 'umd',
dir: path.dirname(pkg.umd),
name: 'index.js',
exports: 'named',
},
],
}),
generateConfig({
targets: 'last 1 chrome versions',
output: [
{
format: 'esm',
dir: path.dirname(pkg.esnext),
preserveModules: true,
entryFileNames: '[name].esnext',
},
],
}),
];

export default config;
5 changes: 0 additions & 5 deletions scripts/.eslintrc.js

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/build.ts

This file was deleted.

85 changes: 0 additions & 85 deletions scripts/build/bundles.ts

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/build/config.ts

This file was deleted.

Loading

0 comments on commit d7a4feb

Please sign in to comment.