Skip to content

Commit fac9149

Browse files
committed
Update to microbundle v0.10.0, enable mini builds
1 parent 48cfaf6 commit fac9149

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
package-lock.json
33
/preact
44
dist
5+
mini
56
yarn.lock

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"umd:main": "dist/htm.umd.js",
77
"module": "dist/htm.mjs",
88
"scripts": {
9-
"build": "npm run -s build:main && npm run -s build:preact && npm run -s build:babel && npm run -s build:babel-transform-jsx",
10-
"build:main": "microbundle src/index.mjs -f es,umd --no-sourcemap --target web && microbundle src/cjs.mjs -f iife --no-sourcemap --target web",
9+
"build": "npm run -s build:main && npm run -s build:mini && npm run -s build:preact && npm run -s build:babel && npm run -s build:babel-transform-jsx",
10+
"build:main": "microbundle src/index.mjs -f es,umd --no-sourcemap --target web --define HTM_MODE=default && microbundle src/cjs.mjs -f iife --no-sourcemap --target web --define HTM_MODE=default",
11+
"build:mini": "microbundle src/index.mjs -o ./mini/index.js -f es,umd --no-sourcemap --target web --define HTM_MODE=mini && microbundle src/cjs.mjs -o ./mini/index.js -f iife --no-sourcemap --target web --define HTM_MODE=mini",
1112
"build:preact": "cd src/integrations/preact && npm run build",
1213
"build:babel": "cd packages/babel-plugin-htm && npm run build",
1314
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-htm && npm run build",
@@ -16,6 +17,7 @@
1617
},
1718
"files": [
1819
"dist",
20+
"mini",
1921
"preact",
2022
"src"
2123
],
@@ -71,7 +73,7 @@
7173
"eslint": "^5.2.0",
7274
"eslint-config-developit": "^1.1.1",
7375
"jest": "^24.1.0",
74-
"microbundle": "^0.8.3",
76+
"microbundle": "^0.10.0",
7577
"preact": "^8.4.2"
7678
},
7779
"dependencies": {},

packages/babel-plugin-htm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
"htm": "^2.0.0"
3333
},
3434
"devDependencies": {
35-
"microbundle": "^0.8.3"
35+
"microbundle": "^0.10.0"
3636
}
3737
}

packages/babel-plugin-transform-jsx-to-htm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
"license": "Apache-2.0",
2929
"homepage": "https://github.com/developit/htm/tree/master/packages/babel-plugin-transform-jsx-to-htm",
3030
"devDependencies": {
31-
"microbundle": "^0.8.3"
31+
"microbundle": "^0.10.0"
3232
}
3333
}

src/index.mjs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* limitations under the License.
1212
*/
1313

14-
const MINI = false;
14+
/* globals HTM_MODE */
15+
const MINI = typeof HTM_MODE === 'string' && HTM_MODE === 'mini';
1516

1617
const TAG_SET = 1;
1718
const PROPS_SET = 2;
@@ -61,7 +62,7 @@ const build = function(statics) {
6162
let quote = '';
6263
let current = [0];
6364
let char, propName;
64-
65+
6566
const commit = field => {
6667
if (mode === MODE_TEXT && (field || (buffer = buffer.replace(/^\s*\n\s*|\s*\n\s*$/g,'')))) {
6768
if (MINI) {
@@ -183,13 +184,13 @@ const build = function(statics) {
183184
}
184185
}
185186
commit();
186-
187+
187188
if (MINI) {
188189
return current.length > 2 ? current.slice(1) : current[1];
189190
}
190191
return current;
191192
};
192-
193+
193194
const getCacheMap = (statics) => {
194195
let tpl = CACHE.get(statics);
195196
if (!tpl) {
@@ -206,13 +207,13 @@ const getCacheKeyed = (statics) => {
206207
return CACHE[key] || (CACHE[key] = build(statics));
207208
};
208209

209-
const USE_MAP = typeof Map === 'function';
210+
const USE_MAP = !MINI && typeof Map === 'function';
210211
const CACHE = USE_MAP ? new Map() : {};
211212
const getCache = USE_MAP ? getCacheMap : getCacheKeyed;
212213

213-
function cached(statics) {
214+
const cached = function(statics) {
214215
const res = evaluate(this, getCache(statics), arguments, []);
215216
return res.length > 1 ? res : res[0];
216-
}
217+
};
217218

218219
export default MINI ? build : cached;

0 commit comments

Comments
 (0)