Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 4 additions & 0 deletions packages/gatsby-cli/src/create-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ function buildLocalCommands(cli, isLocalSite) {
type: `boolean`,
default: false,
describe: `Build site with link paths prefixed (set prefix in your config).`,
}).option(`no-uglify`, {
type: `boolean`,
default: false,
describe: `Build site without uglifying JS bundles (for debugging).`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may want to change this wording :)

}),
handler: handlerP(
getCommandHandler(`build`, (args, cmd) => {
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type BuildArgs = {
sitePackageJson: object,
browserslist: string[],
prefixPaths: boolean,
noUglify: boolean
}

module.exports = async function build(program: BuildArgs) {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function findBabelPackage(directory) {
* the paths will be absolute so that Babel behaves as expected.
*/
module.exports = async function babelConfig(program, stage) {
const { directory } = program
const { directory, noUglify } = program

let babelrc = findBabelrc(directory) || findBabelPackage(directory)

Expand All @@ -149,7 +149,7 @@ module.exports = async function babelConfig(program, stage) {
require.resolve(`babel-preset-env`),
{
loose: true,
uglify: true,
uglify: !noUglify,
modules: `commonjs`,
targets: {
browsers: program.browserslist,
Expand Down
24 changes: 14 additions & 10 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = async (
// webpack config.
const stage = suppliedStage
const babelConfig = await genBabelConfig(program, suppliedStage)
const { noUglify } = program

function processEnv(stage, defaultNodeEnv) {
debug(`Building env for "${stage}"`)
Expand Down Expand Up @@ -235,7 +236,7 @@ module.exports = async (
.getState()
.pages.map(page => page.componentChunkName)
components = uniq(components)
return [
const plugins = [
// Moment.js includes 100s of KBs of extra localization data by
// default in Webpack that most sites don't want. This line disables
// loading locale modules. This is a practical solution that requires
Expand Down Expand Up @@ -315,8 +316,15 @@ module.exports = async (
filename: `chunk-manifest.json`,
manifestVariable: `webpackManifest`,
}),
// Minify Javascript.
new webpack.optimize.UglifyJsPlugin({
// Ensure module order stays the same. Supposibly fixed in webpack 2.0.
new webpack.optimize.OccurenceOrderPlugin(),
new GatsbyModulePlugin(),
// new WebpackStableModuleIdAndHash({ seed: 9, hashSize: 47 }),
new HashedChunkIdsPlugin(),
];
if(!noUglify) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if pushing UglifyJsPlugin to the end of array will something. Let me know if the original order needs to be preserved.

// Minify JavaScript.
plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true, // React doesn't support IE8
warnings: false,
Expand All @@ -328,13 +336,9 @@ module.exports = async (
comments: false,
screw_ie8: true,
},
}),
// Ensure module order stays the same. Supposibly fixed in webpack 2.0.
new webpack.optimize.OccurenceOrderPlugin(),
new GatsbyModulePlugin(),
// new WebpackStableModuleIdAndHash({ seed: 9, hashSize: 47 }),
new HashedChunkIdsPlugin(),
]
}))
}
return plugins
}
default:
throw new Error(`The state requested ${stage} doesn't exist.`)
Expand Down