Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export default function h(name, attrs, ...children) {
// collapse it into the current object for MAGIC
let { name } = child;
if (name) {
obj[name] = child;
obj[name] = obj[name] ? [obj[name], child].flat() : child
delete child.name;
}
else {
} else {
obj.value = child;
}
});
Expand Down
31 changes: 31 additions & 0 deletions test/arrayFixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "webpack",
"target": "web",
"watch": true,
"entry": {
"path": "src/index.js"
},
"resolve": {
"alias": [
{
"from": "react",
"to": "preact-compat"
},
{
"from": "react-dom",
"to": "preact-compat"
}
]
Comment on lines +9 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readme needs updated too 👏🏼

},
"plugins": {
"uglify-js": {
"opts": {
"compression": true,
"mangle": false
}
},
"custom-plugin": {
"foo": "bar"
}
}
}
55 changes: 36 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
import assert from 'assert';
import h from '../src';
import fixture from './fixture.json';
import arrayFixture from './arrayFixture.json';

// example of an import'd plugin
const CustomPlugin = config => ({
...config,
name: 'custom-plugin'
const CustomPlugin = (config) => ({
...config,
name: 'custom-plugin'
});


var json = (
<webpack target="web" watch>
<entry path="src/index.js" />
<resolve>
<alias from="react" to="preact-compat" />
<alias from="react-dom" to="preact-compat" />
</resolve>
<plugins>
<uglify-js opts={{
compression: true,
mangle: false
}} />
<CustomPlugin foo="bar" />
</plugins>
</webpack>
<webpack target="web" watch>
<entry path="src/index.js" />
<resolve>
<alias from="react-dom" to="preact-compat" />
</resolve>
<plugins>
<uglify-js opts={{
compression: true,
mangle: false,
}} />
<CustomPlugin foo="bar" />
</plugins>
</webpack>
);


assert.deepEqual(json, fixture);

var arrayJson = (
<webpack target="web" watch>
<entry path="src/index.js" />
<resolve>
<alias from="react" to="preact-compat" />
<alias from="react-dom" to="preact-compat" />
</resolve>
<plugins>
<uglify-js opts={{
compression: true,
mangle: false,
}} />
<CustomPlugin foo="bar" />
</plugins>
</webpack>
);

assert.deepEqual(arrayJson, arrayFixture);

console.log('✅ success');
process.exit(0);