Skip to content

Commit

Permalink
Revert "Topics/regroup non static files (#6346)"
Browse files Browse the repository at this point in the history
This reverts commit e401237.
  • Loading branch information
KyleAMathews committed Jul 20, 2018
1 parent b1cd381 commit b24e976
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 43 deletions.
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: 6 additions & 10 deletions packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ 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 @@ -199,7 +197,6 @@ 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 @@ -228,7 +225,7 @@ export default (pagePath, callback) => {
as="script"
rel={script.rel}
key={script.name}
href={urlJoin(pathPrefix, pathToGroupScripts, script.name)}
href={urlJoin(pathPrefix, script.name)}
/>
)
})
Expand All @@ -252,22 +249,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, pathToGroupStyles, style.name)}
href={urlJoin(pathPrefix, style.name)}
/>
)
} else {
headComponents.unshift(
<style
data-href={urlJoin(pathPrefix, style.name.slice(2))}
data-href={urlJoin(pathPrefix, style.name)}
dangerouslySetInnerHTML={{
__html: fs.readFileSync(
join(process.cwd(), `public`, pathToGroupStyles, style.name),
join(process.cwd(), `public`, style.name),
`utf-8`
),
}}
Expand Down Expand Up @@ -296,9 +294,7 @@ 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}${pathToGroupScripts}${JSON.stringify(
s.name
).slice(1, -1)}`
const scriptPath = `${pathPrefix}${JSON.stringify(s.name).slice(1, -1)}`
return <script key={scriptPath} src={scriptPath} async />
})

Expand Down
4 changes: 1 addition & 3 deletions packages/gatsby/src/commands/build-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ module.exports = async (program: any, activity: any) => {
if (e) {
return reject(e)
}

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

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

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

const outputFile = `${directory}/public/render-page.js`
if (stats.hasErrors()) {
let webpackErrors = stats.toJson().errors
console.log(`here`, webpackErrors[0])
Expand Down
12 changes: 3 additions & 9 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,7 @@ module.exports = async ({
stage: Stage,
program: any,
}): Promise<WebpackUtilsOptions> => {
/**
* the leading `../` for assetRelativeRoot is required to ensure
* the static files extracted by webpack are not part of the
* "build-javascript" output path of `/js`. The same technique is
* used for CSS
*/
const assetRelativeRoot = `../static/`
const assetRelativeRoot = `static/`
const vendorRegex = /(node_modules|bower_components)/
const supportedBrowsers = program.browserlist

Expand Down Expand Up @@ -449,8 +443,8 @@ module.exports = async ({
*/
plugins.extractText = options =>
new MiniCssExtractPlugin({
filename: `../css/[name].[contenthash].css`,
chunkFilename: `../css/[name].[contenthash].css`,
filename: `[name].[contenthash].css`,
chunkFilename: `[name].[contenthash].css`,
...options,
})

Expand Down
26 changes: 9 additions & 17 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ 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 @@ -126,20 +113,24 @@ 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`,
path: getOutputPaths().path,
publicPath: getOutputPaths().publicPath,
publicPath: program.prefixPaths
? `${store.getState().config.pathPrefix}/`
: `/`,
}
case `build-javascript`:
return {
filename: `[name]-[chunkhash].js`,
chunkFilename: `[name]-[chunkhash].js`,
path: getOutputPaths().path,
publicPath: getOutputPaths().publicPath,
path: directoryPath(`public`),
publicPath: program.prefixPaths
? `${store.getState().config.pathPrefix}/`
: `/`,
}
default:
throw new Error(`The state requested ${stage} doesn't exist.`)
Expand Down Expand Up @@ -240,6 +231,7 @@ module.exports = async (
)
}
}

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

0 comments on commit b24e976

Please sign in to comment.