Skip to content

Instantly share code, notes, and snippets.

@jxnblk
Created May 24, 2018 15:36
Show Gist options
  • Save jxnblk/bd9429d80eb8d8bdd0eda461fd088fd8 to your computer and use it in GitHub Desktop.
Save jxnblk/bd9429d80eb8d8bdd0eda461fd088fd8 to your computer and use it in GitHub Desktop.
diff --git a/src/bunnies.examples.js b/src/bunnies.examples.js
index f8a9f55..992637a 100644
--- a/src/bunnies.examples.js
+++ b/src/bunnies.examples.js
@@ -1,3 +1,3 @@
import {bunnies} from './bunnies'
-export const capitalBunnies = bunnies.map(b => b.toUpperCase())
+export const capitalBunnies = bunnies.map(b => 'boop, ' + b.toUpperCase())
diff --git a/src/index.js b/src/index.js
index 7b09172..852c3c2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,31 +1,33 @@
-const context = require.context('.', true, /\/.*\.examples\.js/)
+const context = require.context('.', true, /\.examples\.js$/)
console.log(context.keys())
const root = document.getElementById('root')
-function renderThings() {
- const allThings = context.keys().map(path => context(path))
- root.innerHTML = `<pre>${JSON.stringify(allThings, null, 2)}</pre>`
+function renderThings(things) {
+ root.innerHTML = `<pre>${JSON.stringify(things, null, 2)}</pre>`
}
-renderThings()
+const allThings = context.keys().map(path => context(path))
+renderThings(allThings)
-if (module.hot) {
+if (module.hot && module.hot.accept) {
// what I want to be able to do:
- module.hot.accept(context.keys(), () => {
+ module.hot.accept(context.id, () => {
// this is never called
- renderThings()
+ const nextContext = require.context('.', true, /\.examples\.js$/)
+ const nextThings = nextContext.keys().map(nextContext)
+ renderThings(nextThings)
})
// I've also tried
// module.hot.accept()
// module.hot.accept(context.id, () => {})
// not even this works.
- module.hot.accept('./bats.examples.js', () => {
- // this is never called
- console.log('bats!')
- })
+ //module.hot.accept('./bats.examples.js', () => {
+ // // this is never called
+ // console.log('bats!')
+ //})
// These don't work. I get a full page refresh with a warning that the changed
// file is not accepted and a gnarly error like:
diff --git a/webpack.config.js b/webpack.config.js
index d9d65d2..73bcf48 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -18,7 +18,7 @@ module.exports = (env = process.env.NODE_ENV || 'development') => {
mode: prod ? 'production' : 'development',
devtool: prod ? 'source-map' : 'cheap-module-source-map',
plugins: removeEmpty([
- prod ? null : new webpack.HotModuleReplacementPlugin()
+ // prod ? null : new webpack.HotModuleReplacementPlugin()
]),
serve: serve
? {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment