Skip to content

Commit

Permalink
remove modules that is the relative path. (#7934)
Browse files Browse the repository at this point in the history
* remove modules that is the relative path.

* feat: replace uglify-es with terser

* fix: run css minification after styled are processed

* Update package.json

* remove deleted flow type fields
  • Loading branch information
jquense authored and pieh committed Sep 13, 2018
1 parent 0673c6c commit 4be5cfd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"copyfiles": "^1.2.0",
"core-js": "^2.5.0",
"css-loader": "^1.0.0",
"cssnano": "^4.0.2",
"debug": "^3.1.0",
"del": "^3.0.0",
"detect-port": "^1.2.1",
Expand Down Expand Up @@ -94,6 +93,7 @@
"null-loader": "^0.1.1",
"opentracing": "^0.14.3",
"opn": "^5.3.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"parse-filepath": "^1.0.1",
"physical-cpu-count": "^2.0.0",
"postcss-flexbugs-fixes": "^3.0.0",
Expand All @@ -112,8 +112,8 @@
"socket.io": "^2.0.3",
"string-similarity": "^1.2.0",
"style-loader": "^0.21.0",
"terser-webpack-plugin": "^1.0.2",
"type-of": "^2.0.1",
"uglifyjs-webpack-plugin": "^1.2.4",
"url-loader": "^1.0.1",
"uuid": "^3.1.0",
"v8-compile-cache": "^1.1.0",
Expand Down
29 changes: 11 additions & 18 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow
const os = require(`os`)

const autoprefixer = require(`autoprefixer`)
const flexbugs = require(`postcss-flexbugs-fixes`)
const UglifyPlugin = require(`uglifyjs-webpack-plugin`)
const TerserPlugin = require(`terser-webpack-plugin`)
const MiniCssExtractPlugin = require(`mini-css-extract-plugin`)
const OptimizeCssAssetsPlugin = require(`optimize-css-assets-webpack-plugin`)

const builtinPlugins = require(`./webpack-plugins`)
const eslintConfig = require(`./eslint-config`)
Expand Down Expand Up @@ -54,8 +54,6 @@ export type LoaderUtils = {
postcss: LoaderResolver<{
browsers?: string[],
plugins?: Array<any> | ((loader: any) => Array<any>),
minimize?: boolean,
cssnano?: any,
}>,

file: LoaderResolver<*>,
Expand Down Expand Up @@ -204,13 +202,7 @@ module.exports = async ({
},

postcss: (options = {}) => {
let {
cssnano,
plugins,
browsers = supportedBrowsers,
minimize = PRODUCTION,
...postcssOpts
} = options
let { plugins, browsers = supportedBrowsers, ...postcssOpts } = options

return {
loader: require.resolve(`postcss-loader`),
Expand All @@ -222,11 +214,10 @@ module.exports = async ({
(typeof plugins === `function` ? plugins(loader) : plugins) || []

return [
minimize && require(`cssnano`)(cssnano),
flexbugs,
autoprefixer({ browsers, flexbox: `no-2009` }),
...plugins,
].filter(Boolean)
]
},
...postcssOpts,
},
Expand Down Expand Up @@ -428,23 +419,25 @@ module.exports = async ({
* Minify javascript code without regard for IE8. Attempts
* to parallelize the work to save time. Generally only add in Production
*/
plugins.uglify = ({ uglifyOptions, ...options } = {}) =>
new UglifyPlugin({
plugins.minifyJs = ({ terserOptions, ...options } = {}) =>
new TerserPlugin({
cache: true,
parallel: os.cpus().length - 1,
parallel: true,
exclude: /\.min\.js/,
sourceMap: true,
uglifyOptions: {
terserOptions: {
compress: {
drop_console: true,
},
ecma: 8,
ie8: false,
...uglifyOptions,
...terserOptions,
},
...options,
})

plugins.minifyCss = (options = {}) => new OptimizeCssAssetsPlugin(options)

/**
* Extracts css requires into a single file;
* includes some reasonable defaults
Expand Down
23 changes: 6 additions & 17 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,6 @@ module.exports = async (
])
break
case `build-javascript`: {
// Minify Javascript only if needed.
configPlugins = program.noUglify
? configPlugins
: configPlugins.concat([
plugins.uglify({
uglifyOptions: {
compress: {
drop_console: false,
},
},
}),
])
configPlugins = configPlugins.concat([
plugins.extractText(),
// Write out stats object mapping named dynamic imports (aka page
Expand Down Expand Up @@ -374,9 +362,6 @@ module.exports = async (
modules: [
directoryPath(path.join(`node_modules`)),
`node_modules`,
// This is head scratching - without it css modules in production will fail
// to find module with relative path
`./`,
],
alias: {
gatsby$: directoryPath(path.join(`.cache`, `gatsby-browser-entry.js`)),
Expand Down Expand Up @@ -430,7 +415,7 @@ module.exports = async (
// https://github.com/defunctzombie/package-browser-field-spec); setting
// the target tells webpack which file to include, ie. browser vs main.
target: stage === `build-html` || stage === `develop-html` ? `node` : `web`,
profile: stage === `production`,

devtool: getDevtool(),
// Turn off performance hints as we (for now) don't want to show the normal
// webpack output anywhere.
Expand All @@ -455,7 +440,11 @@ module.exports = async (
splitChunks: {
name: false,
},
minimize: !program.noUglify,
minimizer: [
// TODO: maybe this option should be noMinimize?
!program.noUglify && plugins.minifyJs(),
plugins.minifyCss(),
].filter(Boolean),
}
}

Expand Down
57 changes: 53 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5106,9 +5106,9 @@ cssnano@4.0.4:
is-resolvable "^1.0.0"
postcss "^6.0.0"

cssnano@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-4.0.2.tgz#0e79a1829afb6583744ba705fd62516fbfd4fda7"
cssnano@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-4.1.0.tgz#682c37b84b9b7df616450a5a8dc9269b9bd10734"
dependencies:
cosmiconfig "^5.0.0"
cssnano-preset-default "^4.0.0"
Expand Down Expand Up @@ -6974,6 +6974,14 @@ find-cache-dir@^1.0.0:
make-dir "^1.0.0"
pkg-dir "^2.0.0"

find-cache-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.0.0.tgz#4c1faed59f45184530fb9d7fa123a4d04a98472d"
dependencies:
commondir "^1.0.1"
make-dir "^1.0.0"
pkg-dir "^3.0.0"

find-up@^1.0.0, find-up@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
Expand Down Expand Up @@ -9903,6 +9911,13 @@ kind-of@^6.0.0, kind-of@^6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"

last-call-webpack-plugin@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555"
dependencies:
lodash "^4.17.5"
webpack-sources "^1.1.0"

latest-version@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-3.1.0.tgz#a205383fea322b33b5ae3b18abee0dc2f356ee15"
Expand Down Expand Up @@ -11758,6 +11773,13 @@ optimist@^0.6.1:
minimist "~0.0.1"
wordwrap "~0.0.2"

optimize-css-assets-webpack-plugin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.1.tgz#9eb500711d35165b45e7fd60ba2df40cb3eb9159"
dependencies:
cssnano "^4.1.0"
last-call-webpack-plugin "^3.0.0"

optionator@^0.8.1, optionator@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"
Expand Down Expand Up @@ -12351,6 +12373,12 @@ pkg-dir@^2.0.0:
dependencies:
find-up "^2.1.0"

pkg-dir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"
dependencies:
find-up "^3.0.0"

pkg-up@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-1.0.0.tgz#3e08fb461525c4421624a33b9f7e6d0af5b05a26"
Expand Down Expand Up @@ -14765,7 +14793,7 @@ source-map-support@^0.5.0:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-support@^0.5.9:
source-map-support@^0.5.9, source-map-support@~0.5.6:
version "0.5.9"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f"
dependencies:
Expand Down Expand Up @@ -15584,6 +15612,27 @@ term-size@^1.2.0:
dependencies:
execa "^0.7.0"

terser-webpack-plugin@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.0.2.tgz#b62dfdc4e59b0b5093665a765b234645b598d1a5"
dependencies:
cacache "^11.0.2"
find-cache-dir "^2.0.0"
schema-utils "^1.0.0"
serialize-javascript "^1.4.0"
source-map "^0.6.1"
terser "^3.8.1"
webpack-sources "^1.1.0"
worker-farm "^1.5.2"

terser@^3.8.1:
version "3.8.2"
resolved "https://registry.yarnpkg.com/terser/-/terser-3.8.2.tgz#48b880f949f8d038aca4dfd00a37c53d96ecf9fb"
dependencies:
commander "~2.17.1"
source-map "~0.6.1"
source-map-support "~0.5.6"

test-exclude@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-1.1.0.tgz#f5ddd718927b12fd02f270a0aa939ceb6eea4151"
Expand Down

0 comments on commit 4be5cfd

Please sign in to comment.