Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
fix(html-entry): fix json assets support in html entry (#619)
Browse files Browse the repository at this point in the history
* use file-loader to handle static assets in html entry

* file-loader is already used
  • Loading branch information
saltysugar authored and egoist committed Aug 9, 2019
1 parent 7ba239d commit 91dfd21
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/html-entry/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ exports.apply = api => {
server = context.server
})

api.hook('createWebpackChain', chain => {
chain.module
.rule('import-json-from-html-entry')
.resourceQuery(/imported-from-html-entry/)
.test(/\.json$/)
.type('javascript/auto')
})

api.hook('createConfig', config => {
if (!Array.isArray(config.entry)) {
return
Expand Down Expand Up @@ -119,9 +127,12 @@ function writeTempFile({ tempFile, htmlFile, restFiles }) {
${staticAssets
.map((file, index) => {
const query = file.includes('?')
? `&imported-from-html-entry`
: `?imported-from-html-entry`
return `require("!file-loader?name=assets/static/html-static-asset/${index}--[name].[ext]!${slash(
file
)}")`
)}${query}")`
})
.join('\n')}
${restFiles
Expand Down

0 comments on commit 91dfd21

Please sign in to comment.