Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
}
}
}
16 changes: 10 additions & 6 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,23 @@ 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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this line? See #6384

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 +293,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
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ module.exports = async ({
*/
plugins.extractText = options =>
new MiniCssExtractPlugin({
filename: `[name].[contenthash].css`,
chunkFilename: `[name].[contenthash].css`,
filename: `../css/[name].[contenthash].css`,
Copy link
Contributor

Choose a reason for hiding this comment

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

why is ../css/ needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, the css is generated in the stage build-javascript using the MiniCssExtractPlugin, which grabs the output path from webpack's config webpackConfig.output.path.

From what I could tell, there's no way of changing the output path (only publicPath?) using MiniCssExtractPlugin so adjusting the filenames is a workaround.

What's happening is the system things it's putting the CSS into the /js folder, but it actually goes back into the root, and creates a /css folder to place the CSS files in.

If there's a different way to handle this, such as creating build-css or a different webpackConfig.output.path during the time of CSS generation that would solve this workaround.

chunkFilename: `../css/[name].[contenthash].css`,
...options,
})

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