-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding dev-libs attribute for automatic overrides to dev versions (#8)
* Adding dev-libs attribute for automatic overrides to dev versions * Documentation * Self review * Self review
- Loading branch information
1 parent
f19b0db
commit 724d9fd
Showing
8 changed files
with
315 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ | |
"author": "Joel Denning <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c", | ||
"watch": "rollup -c --watch", | ||
"test": "npm run build && copyfiles test/index.html dist -f && serve .", | ||
"build": "yarn clean && cross-env NODE_ENV=production rollup -c", | ||
"build:dev": "yarn clean && cross-env NODE_ENV=development rollup -c", | ||
"clean": "rimraf dist", | ||
"watch": "cross-env NODE_ENV=development rollup -c --watch", | ||
"test": "concurrently yarn:watch 'copyfiles test/index.html dist -f' 'serve .'", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"husky": { | ||
|
@@ -27,7 +29,9 @@ | |
"@babel/plugin-proposal-class-properties": "^7.5.5", | ||
"@babel/plugin-transform-react-jsx": "^7.3.0", | ||
"@babel/preset-env": "^7.6.3", | ||
"concurrently": "^5.0.0", | ||
"copyfiles": "^2.1.1", | ||
"cross-env": "^6.0.3", | ||
"husky": "^3.0.9", | ||
"preact": "^10.0.4", | ||
"prettier": "^1.18.2", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { h, Component } from "preact"; | ||
import { getDefaultMap } from "./list/list.component"; | ||
|
||
export default class DevLibOverrides extends Component { | ||
componentDidMount() { | ||
getDefaultMap().then(addDevLibOverrides); | ||
} | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
const devLibs = { | ||
react: url => url.replace("production.min", "development"), | ||
"react-dom": url => url.replace("production.min", "development") | ||
}; | ||
|
||
function addDevLibOverrides(notOverriddenMap) { | ||
Object.keys(notOverriddenMap.imports) | ||
.filter(libName => devLibs[libName]) | ||
.forEach(libName => { | ||
window.importMapOverrides.addOverride( | ||
libName, | ||
devLibs[libName](notOverriddenMap.imports[libName]) | ||
); | ||
}); | ||
} | ||
|
||
export function overridesBesidesDevLibs() { | ||
return ( | ||
Object.keys(window.importMapOverrides.getOverrideMap().imports).filter( | ||
k => !devLibs[k] | ||
).length > 0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,15 @@ | |
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"a": "./a.js" | ||
"a": "./a.js", | ||
"react": "https://cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js", | ||
"react-dom": "https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js" | ||
} | ||
} | ||
</script> | ||
<script src="/import-map-overrides.js"></script> | ||
</head> | ||
<body> | ||
<import-map-overrides-full></import-map-overrides-full> | ||
<import-map-overrides-full dev-libs></import-map-overrides-full> | ||
</body> | ||
</html> |
Oops, something went wrong.