Skip to content

Commit

Permalink
Whitelist page types + add image loader (#357)
Browse files Browse the repository at this point in the history
* Update dependencies
* Only require file types that Gatsby designates as possible pages
* Add Webpack configuration for images
* Also remove now unneeded null-loader config for various assets.
* Copy a few more types of assets from 'pages' to 'public'
  • Loading branch information
KyleAMathews authored Jul 20, 2016
1 parent 4bc03a7 commit 0c4b7b3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 61 deletions.
1 change: 1 addition & 0 deletions lib/isomorphic/create-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = (files, pagesReq) => {

const staticFileTypes = [
'md',
'markdown',
'html',
'json',
'yaml',
Expand Down
17 changes: 3 additions & 14 deletions lib/utils/glob-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ import glob from 'glob'
import buildPage from './build-page'
const debug = require('debug')('gatsby:glob')

import pageFileTypes from './page-file-types'

function globQuery (directory) {
// Make this list easy to modify through the config?
// Or just keep adding extensions...?
const fileTypesToGlob = [
'coffee',
'cjsx',
'jsx',
'js',
'md',
'html',
'json',
'yaml',
'toml',
]
const fileGlobQuery = fileTypesToGlob.map((type) => `*.${type}`)
const fileGlobQuery = pageFileTypes.map((type) => `*.${type}`)
const joinedFileQuery = fileGlobQuery.join('|')
return `${directory}/pages/**/?(${joinedFileQuery})`
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/load-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// This file is auto-written and used by Gatsby to require
// files from your pages directory.
module.exports = function (callback) {
let context = require.context('./pages', true)
let context = require.context('./pages', true, /(coffee|cjsx|jsx|js|markdown|md|html|json|yaml|toml)$/) // eslint-disable-line
if (module.hot) {
module.hot.accept(context.id, () => {
context = require.context('./pages', true)
context = require.context('./pages', true, /(coffee|cjsx|jsx|js|markdown|md|html|json|yaml|toml)$/) // eslint-disable-line
return callback(context)
})
}
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/page-file-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const pageFileTypes = [
'coffee',
'cjsx',
'jsx',
'js',
'markdown',
'md',
'html',
'json',
'yaml',
'toml',
]

export default pageFileTypes
3 changes: 2 additions & 1 deletion lib/utils/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ module.exports = (program, cb) => {
}

// Copy static assets to public folder.
const globString = `${directory}/pages/**/?(*.jpg|*.png|*.pdf|*.gif|*.ico|*.svg)`
const assetTypes = '*.jpg|*.png|*.pdf|*.gif|*.ico|*.svg|*.pdf|*.txt|CNAME'
const globString = `${directory}/pages/**/?(${assetTypes})`
return glob(globString, null, (e, files) =>
async.map(files, copy, (error, results) =>
cb(error, results)
Expand Down
38 changes: 9 additions & 29 deletions lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,38 +223,22 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
test: /\.yaml/,
loaders: ['json', 'yaml'],
})
config.loader('png', {
test: /\.png$/,
loader: 'null',
})
config.loader('jpg', {
test: /\.jpg$/,
loader: 'null',
})
config.loader('gif', {
test: /\.gif$/,
loader: 'null',
})
config.loader('ico', {
test: /\.ico$/,
loader: 'null',
})
config.loader('pdf', {
test: /\.pdf$/,
loader: 'null',
})
config.loader('txt', {
test: /\.txt$/,
loader: 'null',
})
config.loader('config', {
test: /config\.toml/,
loader: 'config',
query: {
directory,
},
})
// Font loaders
// Image loaders.
config.loader('images', {
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'url-loader?limit=10000',
'image-webpack-loader?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}', // eslint-disable-line
],
})
// Font loaders.
config.loader('woff', {
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&minetype=application/font-woff',
Expand All @@ -267,10 +251,6 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
test: /\.(eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
})
config.loader('svg', {
test: /\.(svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
})

const cssModulesConf = 'css?modules&minimize&importLoaders=1'
const cssModulesConfDev =
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,33 @@
"postcss-reporter": "^1.4.1",
"process-finder": "^1.0.0",
"raw-loader": "^0.5.1",
"react": "^15.2.0",
"react": "^15.2.1",
"react-document-title": "^2.0.1",
"react-dom": "^15.2.0",
"react-dom": "^15.2.1",
"react-hot-loader": "^1.3.0",
"react-router": "^2.5.2",
"react-router-scroll": "^0.2.0",
"react-router": "^2.6.0",
"react-router-scroll": "^0.2.1",
"sass-loader": "^3.1.2",
"slash": "^1.0.0",
"static-site-generator-webpack-plugin": "^2.1.0",
"style-loader": "^0.13.0",
"toml": "^2.2.2",
"toml-loader": "^1.0.0",
"tracer": "^0.8.3",
"typography": "^0.10.5",
"typography": "^0.11.7",
"url-loader": "^0.5.7",
"webpack": "^1.13.1",
"webpack-configurator": "^0.3.0",
"webpack-hot-middleware": "^2.12.0",
"webpack-hot-middleware": "^2.12.1",
"webpack-require": "0.0.16",
"yaml-loader": "^0.2.0"
"yaml-loader": "^0.3.0"
},
"devDependencies": {
"ava": "^0.15.2",
"ava-http": "^0.2.1",
"babel-cli": "^6.9.0",
"babel-eslint": "^6.1.0",
"babel-plugin-lodash": "^3.2.0",
"babel-eslint": "^6.1.2",
"babel-plugin-lodash": "^3.2.5",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-register": "^6.9.0",
"bluebird": "^3.4.1",
Expand All @@ -95,15 +95,15 @@
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-ava": "^2.5.0",
"eslint-plugin-flow-vars": "^0.4.0",
"eslint-plugin-flowtype": "^2.3.0",
"eslint-plugin-import": "^1.10.2",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-flowtype": "^2.3.1",
"eslint-plugin-import": "^1.11.0",
"eslint-plugin-jsx-a11y": "^1.5.5",
"eslint-plugin-react": "^5.2.2",
"flow-bin": "^0.28.0",
"flow-bin": "^0.29.0",
"iflow-debug": "^1.0.15",
"iflow-lodash": "^1.1.17",
"iflow-lodash": "^1.1.18",
"iflow-react-router": "^1.1.17",
"nyc": "^6.6.1"
"nyc": "^7.0.0"
},
"engines": {
"node": ">0.12.0"
Expand Down

0 comments on commit 0c4b7b3

Please sign in to comment.