Skip to content

Commit fd8226b

Browse files
authored
Multi Output (#252)
1 parent 70c14cd commit fd8226b

File tree

5 files changed

+77
-59
lines changed

5 files changed

+77
-59
lines changed

lib/plugin.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,23 @@ module.exports = class SpikeWebpackPlugin {
8282
outputPath = outputPath.replace(/(.*)?(\..+?$)/, `$1.${f.extension}`)
8383
}
8484

85-
// and hand off the file to webpack for emission!
86-
compilation.assets[outputPath] = {
87-
source: () => { return src },
88-
size: () => { return src.length }
85+
if (dep._outputMultiple) {
86+
// if we have an outputMultiple flag, that means more than one
87+
// output (shocking, i know)
88+
const sources = JSON.parse(src)
89+
for (let k in sources) {
90+
const multiOutPath = outputPath.replace(/\.html/, `.${k}.html`)
91+
compilation.assets[multiOutPath] = {
92+
source: () => { return sources[k] },
93+
size: () => { return sources[k].length }
94+
}
95+
}
96+
} else {
97+
// otherwise, send off the single file to webpack for emission
98+
compilation.assets[outputPath] = {
99+
source: () => { return src },
100+
size: () => { return src.length }
101+
}
89102
}
90103
})
91104

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"babel-core": "^6.25.0",
1313
"babel-loader": "^7.1.1",
14-
"browser-sync": "^2.18.12",
14+
"browser-sync": "^2.18.13",
1515
"browser-sync-webpack-plugin": "^1.2.0",
1616
"filewrap": "^1.0.0",
1717
"glob": "^7.1.2",
@@ -23,9 +23,9 @@
2323
"micromatch": "^3.0.4",
2424
"mkdirp": "^0.5.1",
2525
"postcss-loader": "^2.0.6",
26-
"reshape-loader": "^1.0.0",
26+
"reshape-loader": "^1.1.0",
2727
"rimraf": "^2.6.1",
28-
"source-loader": "^0.2.0",
28+
"source-loader": "^1.0.0",
2929
"spike-util": "^1.3.0",
3030
"sprout": "^1.2.1",
3131
"webpack": "^3.3.0",
@@ -41,6 +41,7 @@
4141
"postcss-color-gray": "^4.0.0",
4242
"postcss-import": "^10.0.0",
4343
"reshape-custom-elements": "^0.1.0",
44+
"reshape-expressions": "^0.1.5",
4445
"snazzy": "^7.0.0",
4546
"standard": "^10.0.2",
4647
"sugarml": "^0.6.0",

test/fixtures/multi/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{{ greeting }}</p>

test/multi.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const test = require('ava')
2+
const path = require('path')
3+
const fs = require('fs')
4+
const exp = require('reshape-expressions')
5+
const {compileFixture} = require('./_helpers')
6+
7+
test('emits compile errors correctly', (t) => {
8+
return compileFixture(t, 'multi', {
9+
reshape: {
10+
plugins: [exp()],
11+
multi: [
12+
{ locals: { greeting: 'hello' }, name: 'en' },
13+
{ locals: { greeting: 'hola' }, name: 'es' }
14+
]
15+
}
16+
}).then(({res, publicPath}) => {
17+
const src1 = fs.readFileSync(path.join(publicPath, 'index.en.html'), 'utf8')
18+
const src2 = fs.readFileSync(path.join(publicPath, 'index.es.html'), 'utf8')
19+
t.is(src1.trim(), '<p>hello</p>')
20+
t.is(src2.trim(), '<p>hola</p>')
21+
})
22+
})

yarn.lock

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,9 @@ browser-sync-webpack-plugin@^1.2.0:
872872
dependencies:
873873
lodash "^4"
874874

875-
browser-sync@^2.18.12:
876-
version "2.18.12"
877-
resolved "https://registry.yarnpkg.com/browser-sync/-/browser-sync-2.18.12.tgz#bbaa0a17a961e2b5f0a8e760e695027186664779"
875+
browser-sync@^2.18.13:
876+
version "2.18.13"
877+
resolved "https://registry.yarnpkg.com/browser-sync/-/browser-sync-2.18.13.tgz#c28dc3eb3be67c97a907082b772a37f915c14d7d"
878878
dependencies:
879879
browser-sync-client "2.5.1"
880880
browser-sync-ui "0.6.3"
@@ -888,7 +888,7 @@ browser-sync@^2.18.12:
888888
fs-extra "3.0.1"
889889
http-proxy "1.15.2"
890890
immutable "3.8.1"
891-
localtunnel "1.8.2"
891+
localtunnel "1.8.3"
892892
micromatch "2.3.11"
893893
opn "4.0.2"
894894
portscanner "2.1.1"
@@ -1545,7 +1545,7 @@ [email protected]:
15451545
dependencies:
15461546
ms "0.7.3"
15471547

1548-
debug@^2.1.1, debug@^2.2.0, debug@^2.3.3, debug@^2.6.3, debug@^2.6.8:
1548+
debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.3.3, debug@^2.6.3, debug@^2.6.8:
15491549
version "2.6.8"
15501550
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
15511551
dependencies:
@@ -2839,12 +2839,18 @@ is-arrayish@^0.3.1:
28392839
version "0.3.1"
28402840
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.1.tgz#c2dfc386abaa0c3e33c48db3fe87059e69065efd"
28412841

2842-
is-binary-path@^1.0.0, is-binary-path@^1.0.1:
2842+
is-binary-path@^1.0.0:
28432843
version "1.0.1"
28442844
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898"
28452845
dependencies:
28462846
binary-extensions "^1.0.0"
28472847

2848+
is-binary-path@^2.0.0:
2849+
version "2.0.0"
2850+
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.0.0.tgz#0e61cea6974b24dda8bcc8366ce58a69265d1a36"
2851+
dependencies:
2852+
binary-extensions "^1.0.0"
2853+
28482854
is-buffer@^1.1.5:
28492855
version "1.1.5"
28502856
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
@@ -3353,13 +3359,13 @@ loader-utils@^1.0.2, loader-utils@^1.1.0:
33533359
emojis-list "^2.0.0"
33543360
json5 "^0.5.0"
33553361

3356-
3357-
version "1.8.2"
3358-
resolved "https://registry.yarnpkg.com/localtunnel/-/localtunnel-1.8.2.tgz#913051e8328b51f75ad8a22ad1f5c5b8c599a359"
3362+
3363+
version "1.8.3"
3364+
resolved "https://registry.yarnpkg.com/localtunnel/-/localtunnel-1.8.3.tgz#dcc5922fd85651037d4bde24fd93248d0b24eb05"
33593365
dependencies:
3360-
debug "2.2.0"
3361-
openurl "1.1.0"
3362-
request "2.78.0"
3366+
debug "2.6.8"
3367+
openurl "1.1.1"
3368+
request "2.81.0"
33633369
yargs "3.29.0"
33643370

33653371
locate-path@^2.0.0:
@@ -3752,10 +3758,6 @@ node-pre-gyp@^0.6.36:
37523758
tar "^2.2.1"
37533759
tar-pack "^3.4.0"
37543760

3755-
node-uuid@~1.4.7:
3756-
version "1.4.8"
3757-
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907"
3758-
37593761
37603762
version "3.0.6"
37613763
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
@@ -3937,9 +3939,9 @@ onetime@^2.0.0:
39373939
dependencies:
39383940
mimic-fn "^1.0.0"
39393941

3940-
3941-
version "1.1.0"
3942-
resolved "https://registry.yarnpkg.com/openurl/-/openurl-1.1.0.tgz#e2f2189d999c04823201f083f0f1a7cd8903187a"
3942+
3943+
version "1.1.1"
3944+
resolved "https://registry.yarnpkg.com/openurl/-/openurl-1.1.1.tgz#3875b4b0ef7a52c156f0db41d4609dbb0f94b387"
39433945

39443946
39453947
version "4.0.2"
@@ -4605,31 +4607,6 @@ repeating@^2.0.0:
46054607
dependencies:
46064608
is-finite "^1.0.0"
46074609

4608-
4609-
version "2.78.0"
4610-
resolved "https://registry.yarnpkg.com/request/-/request-2.78.0.tgz#e1c8dec346e1c81923b24acdb337f11decabe9cc"
4611-
dependencies:
4612-
aws-sign2 "~0.6.0"
4613-
aws4 "^1.2.1"
4614-
caseless "~0.11.0"
4615-
combined-stream "~1.0.5"
4616-
extend "~3.0.0"
4617-
forever-agent "~0.6.1"
4618-
form-data "~2.1.1"
4619-
har-validator "~2.0.6"
4620-
hawk "~3.1.3"
4621-
http-signature "~1.1.0"
4622-
is-typedarray "~1.0.0"
4623-
isstream "~0.1.2"
4624-
json-stringify-safe "~5.0.1"
4625-
mime-types "~2.1.7"
4626-
node-uuid "~1.4.7"
4627-
oauth-sign "~0.8.1"
4628-
qs "~6.3.0"
4629-
stringstream "~0.0.4"
4630-
tough-cookie "~2.3.0"
4631-
tunnel-agent "~0.4.1"
4632-
46334610
46344611
version "2.79.0"
46354612
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
@@ -4655,7 +4632,7 @@ [email protected]:
46554632
tunnel-agent "~0.4.1"
46564633
uuid "^3.0.0"
46574634

4658-
request@^2.81.0:
4635+
request@2.81.0, request@^2.81.0:
46594636
version "2.81.0"
46604637
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
46614638
dependencies:
@@ -4722,15 +4699,19 @@ reshape-custom-elements@^0.1.0:
47224699
dependencies:
47234700
reshape-plugin-util reshape/plugin-util
47244701

4702+
reshape-expressions@^0.1.5:
4703+
version "0.1.5"
4704+
resolved "https://registry.yarnpkg.com/reshape-expressions/-/reshape-expressions-0.1.5.tgz#28c12bf35de40263362499cead0b044321e4a78c"
4705+
47254706
reshape-include@^1.0.0:
47264707
version "1.0.0"
47274708
resolved "https://registry.yarnpkg.com/reshape-include/-/reshape-include-1.0.0.tgz#2f75e57e016447c633f48cbb0e2a5ca114275d10"
47284709
dependencies:
47294710
reshape-plugin-util "^0.2.0"
47304711

4731-
reshape-loader@^1.0.0:
4732-
version "1.0.0"
4733-
resolved "https://registry.yarnpkg.com/reshape-loader/-/reshape-loader-1.0.0.tgz#c5bf46ad99715b216f87a1b772c4bc2695121cd6"
4712+
reshape-loader@^1.1.0:
4713+
version "1.1.0"
4714+
resolved "https://registry.yarnpkg.com/reshape-loader/-/reshape-loader-1.1.0.tgz#96d88f7983a4cf6f040e601a7283402cbe3778c9"
47344715
dependencies:
47354716
reshape "^0.4.1"
47364717
reshape-include "^1.0.0"
@@ -5076,11 +5057,11 @@ source-list-map@^2.0.0:
50765057
version "2.0.0"
50775058
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085"
50785059

5079-
source-loader@^0.2.0:
5080-
version "0.2.0"
5081-
resolved "https://registry.yarnpkg.com/source-loader/-/source-loader-0.2.0.tgz#b362d65885d540f069ceecd5ad4fbb67572ab87b"
5060+
source-loader@^1.0.0:
5061+
version "1.0.0"
5062+
resolved "https://registry.yarnpkg.com/source-loader/-/source-loader-1.0.0.tgz#dbe890d46c8429fa7ac358c7e648f7f03cbe8738"
50825063
dependencies:
5083-
is-binary-path "^1.0.1"
5064+
is-binary-path "^2.0.0"
50845065

50855066
source-map-resolve@^0.5.0:
50865067
version "0.5.0"

0 commit comments

Comments
 (0)