Skip to content

Commit

Permalink
build: build esm to dist with fixed imports and mjs extension [#242]
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Nov 10, 2022
1 parent 156e599 commit dde17b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 11 additions & 0 deletions build/esm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

cp -r ./src ./dist/esm
find dist/esm -type f -name "*.js" -print0 | xargs -0 sed -i -r "s/([ie][mx]port [^']+?)'(\\.[^']+)'/\\1'\\2.mjs'/g"
find dist/esm -type f -name "*.js" -print0 | xargs -0 sed -i -r "s/.([cm])js.mjs/.\\1js/g"
for file in ./dist/esm/*.js; do
mv -- "$file" "${file%.js}.mjs"
done
for file in ./dist/esm/**/*.js; do
mv -- "$file" "${file%.js}.mjs"
done
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
"name": "@ecomplus/utils",
"version": "1.5.0-rc.0",
"description": "JS utility functions to E-Com Plus (not only) related apps",
"main": "dist/ecom-utils.node.min.js",
"exports": {
"import": "./src/index.js",
"import": "./dist/esm/index.mjs",
"require": "./dist/ecom-utils.node.min.js"
},
"type": "module",
"main": "dist/ecom-utils.node.min.js",
"types": "./dist/index.d.ts",
"module": "src/index.js",
"browser": "dist/ecom-utils.min.js",
Expand All @@ -16,9 +15,9 @@
"sideEffects": false,
"scripts": {
"serve": "webpack-dev-server",
"build": "node ./build/bin.cjs && npx -p typescript tsc",
"build": "rm -rf ./dist; node ./build/bin.cjs && bash ./build/esm.sh && npx -p typescript tsc",
"doc": "rm -rf ./docs/*; jsdoc ./src -r ./README.md -d ./docs -t ./node_modules/docdash",
"release": "rm -rf ./dist; npm ddp && npm run build && npx standard-version --prerelease rc"
"release": "npm ddp && npm run build && npx standard-version --prerelease rc"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit dde17b8

Please sign in to comment.