Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topics/regroup non static files #6346

Merged
merged 18 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"__PATH_PREFIX__": false,
"___emitter": false
}
}
}
17 changes: 10 additions & 7 deletions packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const createElement = React.createElement

export default (pagePath, callback) => {
const pathPrefix = `${__PATH_PREFIX__}/`
const pathToGroupStyles = `css/`
const pathToGroupScripts = `js/`

let bodyHtml = ``
let headComponents = []
Expand Down Expand Up @@ -193,6 +195,7 @@ export default (pagePath, callback) => {
const scripts = scriptsAndStyles.filter(
script => script.name && script.name.endsWith(`.js`)
)

const styles = scriptsAndStyles.filter(
style => style.name && style.name.endsWith(`.css`)
)
Expand Down Expand Up @@ -221,7 +224,7 @@ export default (pagePath, callback) => {
as="script"
rel={script.rel}
key={script.name}
href={urlJoin(pathPrefix, script.name)}
href={urlJoin(pathPrefix, pathToGroupScripts, script.name)}
/>
)
})
Expand All @@ -245,24 +248,22 @@ export default (pagePath, callback) => {
.forEach(style => {
// Add <link>s for styles that should be prefetched
// otherwise, inline as a <style> tag

if (style.rel === `prefetch`) {
headComponents.push(
<link
as="style"
rel={style.rel}
key={style.name}
href={urlJoin(pathPrefix, style.name)}
href={urlJoin(pathPrefix, pathToGroupStyles, style.name)}
/>
)
} else {
headComponents.unshift(
<style
Copy link
Contributor Author

@brotzky brotzky Jul 12, 2018

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks 👍

type="text/css"
data-href={urlJoin(pathPrefix, style.name)}
data-href={urlJoin(pathPrefix, style.name.slice(2))}
dangerouslySetInnerHTML={{
__html: fs.readFileSync(
join(process.cwd(), `public`, style.name),
join(process.cwd(), `public`, pathToGroupStyles, style.name),
`utf-8`
),
}}
Expand Down Expand Up @@ -291,7 +292,9 @@ export default (pagePath, callback) => {
// Filter out prefetched bundles as adding them as a script tag
// would force high priority fetching.
const bodyScripts = scripts.filter(s => s.rel !== `prefetch`).map(s => {
const scriptPath = `${pathPrefix}${JSON.stringify(s.name).slice(1, -1)}`
const scriptPath = `${pathPrefix}${pathToGroupScripts}${JSON.stringify(
s.name
).slice(1, -1)}`
return <script key={scriptPath} src={scriptPath} async />
})

Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/src/commands/build-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module.exports = async (program: any) => {
if (e) {
return reject(e)
}
const outputFile = `${directory}/public/render-page.js`

const outputFile = `${directory}/public/js/render-page.js`

if (stats.hasErrors()) {
let webpackErrors = stats.toJson().errors.filter(Boolean)
return reject(
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/src/commands/develop-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = async (program: any) => {
if (e) {
return reject(e)
}
const outputFile = `${directory}/public/render-page.js`

const outputFile = `${directory}/public/js/render-page.js`

if (stats.hasErrors()) {
let webpackErrors = stats.toJson().errors
console.log(`here`, webpackErrors[0])
Expand Down
26 changes: 17 additions & 9 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ module.exports = async (
return hmrBasePath + hmrSuffix
}

function getOutputPaths() {
const path = directoryPath(`public/js`)

let publicPath = program.prefixPaths
? `${store.getState().config.pathPrefix}/js/`
: `/js/`

return {
path,
publicPath,
}
}

debug(`Loading webpack config for stage "${stage}"`)
function getOutput() {
switch (stage) {
Expand All @@ -110,24 +123,20 @@ module.exports = async (
// A temp file required by static-site-generator-plugin. See plugins() below.
// Deleted by build-html.js, since it's not needed for production.
return {
path: directoryPath(`public`),
filename: `render-page.js`,
libraryTarget: `umd`,
library: `lib`,
umdNamedDefine: true,
globalObject: `this`,
publicPath: program.prefixPaths
? `${store.getState().config.pathPrefix}/`
: `/`,
path: getOutputPaths().path,
publicPath: getOutputPaths().publicPath,
}
case `build-javascript`:
return {
filename: `[name]-[chunkhash].js`,
chunkFilename: `[name]-[chunkhash].js`,
path: directoryPath(`public`),
publicPath: program.prefixPaths
? `${store.getState().config.pathPrefix}/`
: `/`,
path: getOutputPaths().path,
publicPath: getOutputPaths().publicPath,
}
default:
throw new Error(`The state requested ${stage} doesn't exist.`)
Expand Down Expand Up @@ -228,7 +237,6 @@ module.exports = async (
)
}
}

const webpackStats = {
...stats.toJson({ all: false, chunkGroups: true }),
assetsByChunkName: assets,
Expand Down