Skip to content

Commit

Permalink
Get asset compilation working with ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenImp committed Jun 24, 2023
1 parent 9df880f commit 4b56f09
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 161 deletions.
5 changes: 4 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ module.exports = {
rootDir: "./src"
}
}
}
},
testMatch: [
'<rootDir>/tests/**/*.[jt]s?(x)',
],
};
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@
],
"readmeFilename": "README.md",
"devDependencies": {
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.1",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"benchmark": "^2.1.4",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"rimraf": "^5.0.1",
"rollup": "^3.25.1",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.35.0",
"terser": "^5.18.1",
"ts-jest": "^29.1.0",
"tslib": "^2.5.3",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^5.1.3"
},
"scripts": {
"clean": "rimraf dist/**/*.js dist/**/*.ts dist/**/*.map",
"build:umd": "rollup -c rollup.config.es3.js --format umd -o dist/umd/random-js.js --name Random -m",
"build:esm": "rollup -c rollup.config.js --format esm --sourcemap true -o dist/esm/random-js.js",
"build:umd": "rollup --c --environment BUILD:prod",
"build:dev": "rollup --c --environment BUILD:dev",
"prebuild": "yarn clean",
"build": "yarn build:umd && yarn build:esm",
"minify": "terser --source-map content=dist/umd/random-js.js.map --compress --mangle --output dist/umd/random-js.min.js dist/umd/random-js.js",
"postbuild": "yarn minify",
"build": "yarn build:dev && yarn build:prod",
"watch": "yarn build:dev -- -w",
"benchmark": "for k in benchmark/*.cjs; do node $k; done",
"test": "jest",
"lint": "tslint --project .",
Expand Down
8 changes: 5 additions & 3 deletions rollup.config.es3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import typescript from "rollup-plugin-typescript2";
import typescript from 'rollup-plugin-typescript2';

const inputPath = './src/index.ts';

export default {
input: "./src/index.ts",
input: inputPath,
plugins: [
typescript({
tsconfigOverride: {
Expand All @@ -10,7 +12,7 @@ export default {
declaration: false,
declarationMap: false
},
exclude: ["dist/**", "src/**/*.test.ts"]
exclude: ["dist/**", "**/*.test.ts"]
}
})
]
Expand Down
47 changes: 36 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import typescript from "rollup-plugin-typescript2";
import typescript from "@rollup/plugin-typescript";
import terser from '@rollup/plugin-terser';

export default {
input: "./src/index.ts",
plugins: [
typescript({
tsconfigOverride: {
exclude: ["dist/**", "src/**/*.test.ts"]
}
})
]
};
const production = !process.env.BUILD || (process.env.BUILD === 'prod');
const inputPath = './src/index.ts';
const outputPath = (format, minify = false) => `dist/${format}/random-js${minify ? '.min' : ''}.js`;
const packageName = 'Random';

const plugins = (isProduction = false) => [
typescript(),
// minify for production
//isProduction ? terser({ keep_classnames: true }) : null,
];

export default [
// ESM
{
input: inputPath,
output: {
file: outputPath('esm', production),
format: 'esm',
sourcemap: true,
},
plugins: plugins(production),
},
// UMD
{
input: inputPath,
output: {
file: outputPath('umd', production),
format: 'umd',
name: packageName,
sourcemap: true,
},
plugins: plugins(production),
},
];
7 changes: 2 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"declaration": true,
"declaration": false,
"declarationDir": null,
"rootDir": "./src",
"strict": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noImplicitReturns": true,
// "noFallthroughCasesInSwitch": true
"sourceMap": true
},
"exclude": ["dist/**"]
Expand Down
Loading

0 comments on commit 4b56f09

Please sign in to comment.