Skip to content

Commit

Permalink
Optimize site build by removing sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
themadcreator committed Nov 10, 2016
1 parent 8984b08 commit 730de0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions gulp/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const postcssCopyAssets = require("postcss-copy-assets");
const postcssImport = require("postcss-import");
const postcssUrl = require("postcss-url");

const PROD_MODE = process.env.NODE_ENV === "production";

module.exports = (gulp, plugins, blueprint) => {
const path = require("path");
const COPYRIGHT_HEADER = require("./util/text").COPYRIGHT_HEADER;
Expand Down Expand Up @@ -53,6 +55,7 @@ module.exports = (gulp, plugins, blueprint) => {

const postcssOptions = {
to : blueprint.destPath(project, "dist.css"),
map: { inline: !PROD_MODE },
};
const postcssPlugins = [
// inline all imports
Expand All @@ -73,13 +76,13 @@ module.exports = (gulp, plugins, blueprint) => {
];

return gulp.src(config.srcGlob(project, true))
.pipe(plugins.sourcemaps.init())
.pipe(PROD_MODE ? plugins.util.noop() : plugins.sourcemaps.init())
.pipe(sassCompiler)
.pipe(plugins.postcss(postcssPlugins, postcssOptions))
.pipe(plugins.stripCssComments({ preserve: /^\*/ }))
.pipe(plugins.replace(/\n{3,}/g, "\n\n"))
// see https://github.com/floridoo/vinyl-sourcemaps-apply/issues/11#issuecomment-231220574
.pipe(plugins.sourcemaps.write(undefined, { sourceRoot: null }))
.pipe(PROD_MODE ? plugins.util.noop() : plugins.sourcemaps.write(undefined, { sourceRoot: null }))
.pipe(blueprint.dest(project))
.pipe(plugins.connect.reload());
});
Expand Down
5 changes: 3 additions & 2 deletions gulp/util/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const camelCase = require("lodash/camelCase");
const upperFirst = require("lodash/upperFirst");
const webpack = require("webpack");

const PROD_MODE = process.env.NODE_ENV === "production";
const globalName = (id) => upperFirst(camelCase(id));

const DEFAULT_CONFIG = {
devtool: "source-map",
devtool: PROD_MODE ? undefined : "source-map",
resolve: { extensions: ["", ".js"] },
plugins: [
new webpack.DefinePlugin({
Expand All @@ -25,7 +26,7 @@ const DEFAULT_CONFIG = {

// Default webpack config options with support for TypeScript files
const TYPESCRIPT_CONFIG = {
devtool: "source-map",
devtool: PROD_MODE ? undefined : "source-map",
resolve: { extensions: ["", ".js", ".ts", ".tsx"] },
ts: {
// do not emit declarations since we are bundling
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"scripts": {
"bootstrap": "lerna bootstrap",
"build:landing": "(cd packages/landing; npm run build)",
"build:gulp": "NODE_ENV='\"production\"' gulp build",
"build:site": "npm-run-all build:gulp build:landing copy:docs copy:landing",
"copy:docs": "cp -r packages/docs/dist docs/docs",
"copy:landing": "cp -r packages/landing/dist/* docs/.",
"build:gulp": "NODE_ENV='production' gulp build",
"build:site": "npm-run-all build:gulp build:landing clean:docs copy:docs copy:landing",
"clean:docs": "rm -rf docs && git checkout docs/CNAME",
"copy:docs": "cp -rf packages/docs/dist docs/docs",
"copy:landing": "cp -rf packages/landing/dist/* docs/.",
"serve": "http-server docs"
},
"dependencies": {
Expand Down

1 comment on commit 730de0c

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

Optimize site build by removing sourcemaps

Preview: docs Coverage: core | datetime

Please sign in to comment.