diff --git a/.gitignore b/.gitignore index 4c587426c9..8ed8a1bea2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ jspm_packages # Only keep yarn.lock in the root package-lock.json -**/yarn.lock +./**/yarn.lock # Logs *.log diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 0d10819067..c7bf7ef574 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -1,7 +1,14 @@ import path from 'path' import fs from 'fs' import pify from 'pify' -import _ from 'lodash' +import uniqBy from 'lodash/uniqBy' +import map from 'lodash/map' +import debounce from 'lodash/debounce' +import concat from 'lodash/concat' +import omit from 'lodash/omit' +import uniq from 'lodash/uniq' +import template from 'lodash/template' +import values from 'lodash/values' import chokidar from 'chokidar' import fsExtra from 'fs-extra' import hash from 'hash-sum' @@ -92,7 +99,7 @@ export default class Builder { } normalizePlugins() { - return _.uniqBy( + return uniqBy( this.options.plugins.map((p) => { if (typeof p === 'string') p = { src: p } const pluginBaseName = path.basename(p.src, path.extname(p.src)).replace( @@ -205,7 +212,7 @@ export default class Builder { .join('|'), messages: this.options.messages, splitChunks: this.options.build.splitChunks, - uniqBy: _.uniqBy, + uniqBy, isDev: this.options.dev, debug: this.options.debug, vue: { config: this.options.vue.config }, @@ -411,7 +418,7 @@ export default class Builder { const fileContent = await fsExtra.readFile(src, 'utf8') let content try { - const template = _.template(fileContent, { + const templateFunction = template(fileContent, { imports: { serialize, devalue, @@ -425,7 +432,7 @@ export default class Builder { }, interpolate: /<%=([\s\S]+?)%>/g }) - content = template( + content = templateFunction( Object.assign({}, templateVars, { options: options || {}, custom, @@ -635,11 +642,11 @@ export default class Builder { r(src, `${this.options.dir.pages}/**/*.{vue,js}`) ) } - patterns = _.map(patterns, upath.normalizeSafe) + patterns = map(patterns, upath.normalizeSafe) const options = this.options.watchers.chokidar /* istanbul ignore next */ - const refreshFiles = _.debounce(() => this.generateRoutesAndFiles(), 200) + const refreshFiles = debounce(() => this.generateRoutesAndFiles(), 200) // Watch for src Files this.watchers.files = chokidar @@ -648,18 +655,18 @@ export default class Builder { .on('unlink', refreshFiles) // Watch for custom provided files - let customPatterns = _.concat( + let customPatterns = concat( this.options.build.watch, - ..._.values(_.omit(this.options.build.styleResources, ['options'])) + ...values(omit(this.options.build.styleResources, ['options'])) ) - customPatterns = _.map(_.uniq(customPatterns), upath.normalizeSafe) + customPatterns = map(uniq(customPatterns), upath.normalizeSafe) this.watchers.custom = chokidar .watch(customPatterns, options) .on('change', refreshFiles) } watchServer() { - const nuxtRestartWatch = _.concat( + const nuxtRestartWatch = concat( this.options.serverMiddleware .filter(i => typeof i === 'string') .map(this.nuxt.resolver.resolveAlias), @@ -694,7 +701,7 @@ export default class Builder { // TODO: remove ignore when generateConfig enabled again async generateConfig() /* istanbul ignore next */ { const config = path.resolve(this.options.buildDir, 'build.config.js') - const options = _.omit(this.options, Options.unsafeKeys) + const options = omit(this.options, Options.unsafeKeys) await fsExtra.writeFile( config, `export default ${JSON.stringify(options, null, ' ')}`, diff --git a/packages/builder/src/webpack/base.js b/packages/builder/src/webpack/base.js index 1667b49e0d..5956e1c32f 100644 --- a/packages/builder/src/webpack/base.js +++ b/packages/builder/src/webpack/base.js @@ -1,7 +1,8 @@ import path from 'path' import consola from 'consola' import TimeFixPlugin from 'time-fix-plugin' -import _ from 'lodash' +import clone from 'lodash/clone' +import cloneDeep from 'lodash/cloneDeep' import VueLoader from 'vue-loader' import MiniCssExtractPlugin from 'mini-css-extract-plugin' import WebpackBar from 'webpackbar' @@ -33,7 +34,7 @@ export default class WebpackBaseConfig { } getBabelOptions() { - const options = _.clone(this.options.build.babel) + const options = clone(this.options.build.babel) if (typeof options.presets === 'function') { options.presets = options.presets({ isServer: this.isServer }) @@ -233,7 +234,7 @@ export default class WebpackBaseConfig { } plugins() { - const plugins = [ new VueLoader.VueLoaderPlugin() ] + const plugins = [new VueLoader.VueLoaderPlugin()] Array.prototype.push.apply(plugins, this.options.build.plugins || []) @@ -324,6 +325,6 @@ export default class WebpackBaseConfig { const extendedConfig = this.extendConfig(config) // Clone deep avoid leaking config between Client and Server - return _.cloneDeep(extendedConfig) + return cloneDeep(extendedConfig) } } diff --git a/packages/builder/src/webpack/plugins/vue/client.js b/packages/builder/src/webpack/plugins/vue/client.js index f4a7fe6eb1..df96a35081 100644 --- a/packages/builder/src/webpack/plugins/vue/client.js +++ b/packages/builder/src/webpack/plugins/vue/client.js @@ -1,5 +1,5 @@ import hash from 'hash-sum' -import { uniq } from 'lodash' +import uniq from 'lodash/uniq' import { isJS, isCSS, onEmit } from './util' diff --git a/packages/builder/src/webpack/utils/postcss.js b/packages/builder/src/webpack/utils/postcss.js index 528d3f87b8..51674bbad7 100644 --- a/packages/builder/src/webpack/utils/postcss.js +++ b/packages/builder/src/webpack/utils/postcss.js @@ -1,6 +1,8 @@ import fs from 'fs' import path from 'path' -import _ from 'lodash' +import defaults from 'lodash/defaults' +import merge from 'lodash/merge' +import cloneDeep from 'lodash/cloneDeep' import createResolver from 'postcss-import-resolver' import { isPureObject } from '@nuxt/common' @@ -112,7 +114,7 @@ export default class PostcssConfig { return config } - config = this.normalize(_.cloneDeep(this.postcss)) + config = this.normalize(cloneDeep(this.postcss)) // Apply default plugins if (isPureObject(config)) { @@ -121,10 +123,10 @@ export default class PostcssConfig { delete config.preset } if (Array.isArray(config.plugins)) { - _.defaults(config, this.defaultConfig) + defaults(config, this.defaultConfig) } else { // Keep the order of default plugins - config = _.merge({}, this.defaultConfig, config) + config = merge({}, this.defaultConfig, config) this.loadPlugins(config) } return config diff --git a/packages/common/src/nuxt.config.js b/packages/common/src/nuxt.config.js index 67fe0a72ce..243d998724 100644 --- a/packages/common/src/nuxt.config.js +++ b/packages/common/src/nuxt.config.js @@ -1,6 +1,6 @@ import path from 'path' import fs from 'fs' -import _ from 'lodash' +import capitalize from 'lodash/capitalize' import env from 'std-env' const nuxtDir = fs.existsSync(path.resolve(__dirname, '..', '..', 'package.js')) @@ -22,8 +22,8 @@ export default { nuxt: globalName => `$${globalName}`, context: globalName => `__${globalName.toUpperCase()}__`, pluginPrefix: globalName => globalName, - readyCallback: globalName => `on${_.capitalize(globalName)}Ready`, - loadedCallback: globalName => `_on${_.capitalize(globalName)}Loaded` + readyCallback: globalName => `on${capitalize(globalName)}Ready`, + loadedCallback: globalName => `_on${capitalize(globalName)}Loaded` }, // Server options diff --git a/packages/common/src/options.js b/packages/common/src/options.js index e6487a88ac..aa26990290 100644 --- a/packages/common/src/options.js +++ b/packages/common/src/options.js @@ -1,8 +1,12 @@ import path from 'path' import fs from 'fs' -import _ from 'lodash' +import defaultsDeep from 'lodash/defaultsDeep' +import defaults from 'lodash/defaults' +import pick from 'lodash/pick' +import isObject from 'lodash/isObject' import consola from 'consola' +import { isString } from '@nuxt/common' import { isPureObject, isUrl, guardDir } from './utils' import Modes from './modes' import NuxtConfig from './nuxt.config' @@ -42,7 +46,7 @@ Options.from = function (_options) { options.extensions = [options.extensions] } - options.globalName = (_.isString(options.globalName) && /^[a-zA-Z]+$/.test(options.globalName)) + options.globalName = (isString(options.globalName) && /^[a-zA-Z]+$/.test(options.globalName)) ? options.globalName.toLowerCase() : `nuxt` @@ -54,11 +58,11 @@ Options.from = function (_options) { // const buildDir = options.buildDir || defaults.buildDir // const buildConfig = resolve(options.rootDir, buildDir, 'build.config.js') // if (existsSync(buildConfig)) { - // _.defaultsDeep(options, require(buildConfig)) + // defaultsDeep(options, require(buildConfig)) // } // Apply defaults - _.defaultsDeep(options, NuxtConfig) + defaultsDeep(options, NuxtConfig) // Check srcDir and generate.dir excistence const hasSrcDir = hasValue(options.srcDir) @@ -166,7 +170,7 @@ Options.from = function (_options) { reportOnly: options.debug } if (csp) { - options.render.csp = _.defaults(_.isObject(csp) ? csp : {}, cspDefaults) + options.render.csp = defaults(isObject(csp) ? csp : {}, cspDefaults) } // cssSourceMap @@ -190,7 +194,7 @@ Options.from = function (_options) { } // merge custom env with variables - const eligibleEnvVariables = _.pick(process.env, Object.keys(process.env).filter(k => k.startsWith('NUXT_ENV_'))) + const eligibleEnvVariables = pick(process.env, Object.keys(process.env).filter(k => k.startsWith('NUXT_ENV_'))) Object.assign(options.env, eligibleEnvVariables) // Normalize ignore @@ -218,7 +222,7 @@ Options.from = function (_options) { // Apply mode preset const modePreset = Modes[options.mode || 'universal'] || Modes.universal - _.defaultsDeep(options, modePreset) + defaultsDeep(options, modePreset) // If no server-side rendering, add appear true transition /* istanbul ignore if */ diff --git a/packages/common/src/utils.js b/packages/common/src/utils.js index 730eaec9ab..fe17e0b089 100644 --- a/packages/common/src/utils.js +++ b/packages/common/src/utils.js @@ -1,5 +1,6 @@ import path from 'path' -import _ from 'lodash' +import escapeRegExp from 'lodash/escapeRegExp' +import get from 'lodash/get' import consola from 'consola' export const encodeHtml = function encodeHtml(str) { @@ -145,7 +146,7 @@ export const wChunk = function wChunk(p = '') { } const reqSep = /\//g -const sysSep = _.escapeRegExp(path.sep) +const sysSep = escapeRegExp(path.sep) const normalize = string => string.replace(reqSep, sysSep) export const r = function r(...args) { @@ -335,8 +336,8 @@ export const createRoutes = function createRoutes(files, srcDir, pagesDir) { // Guard dir1 from dir2 which can be indiscriminately removed export const guardDir = function guardDir(options, key1, key2) { - const dir1 = _.get(options, key1, false) - const dir2 = _.get(options, key2, false) + const dir1 = get(options, key1, false) + const dir2 = get(options, key2, false) if ( dir1 && diff --git a/packages/core/src/nuxt.js b/packages/core/src/nuxt.js index dc112deb1b..b2239ed7f9 100644 --- a/packages/core/src/nuxt.js +++ b/packages/core/src/nuxt.js @@ -1,6 +1,6 @@ import https from 'https' import enableDestroy from 'server-destroy' -import _ from 'lodash' +import isPlainObject from 'lodash/isPlainObject' import consola from 'consola' import chalk from 'chalk' @@ -51,7 +51,7 @@ export default class Nuxt { } // Add hooks - if (_.isPlainObject(this.options.hooks)) { + if (isPlainObject(this.options.hooks)) { this.addHooks(this.options.hooks) } else if (typeof this.options.hooks === 'function') { this.options.hooks(this.hook) diff --git a/packages/core/src/renderer.js b/packages/core/src/renderer.js index 258a4ca00f..33348b7aba 100644 --- a/packages/core/src/renderer.js +++ b/packages/core/src/renderer.js @@ -2,7 +2,7 @@ import path from 'path' import crypto from 'crypto' import devalue from '@nuxtjs/devalue' import serveStatic from 'serve-static' -import _ from 'lodash' +import template from 'lodash/template' import fs from 'fs-extra' import { createBundleRenderer } from 'vue-server-renderer' import connect from 'connect' @@ -414,10 +414,13 @@ export default class Renderer { virtualConsole: true, beforeParse(window) { // Mock window.scrollTo - window.scrollTo = () => {} + window.scrollTo = () => { + } } }, opts) - const jsdomErrHandler = (err) => { throw err } + const jsdomErrHandler = (err) => { + throw err + } if (options.virtualConsole) { if (options.virtualConsole === true) { options.virtualConsole = new jsdom.VirtualConsole().sendTo(consola) @@ -452,7 +455,7 @@ export default class Renderer { } const parseTemplate = templateStr => - _.template(templateStr, { + template(templateStr, { interpolate: /{{([\s\S]+?)}}/g }) diff --git a/yarn.lock b/yarn.lock index 72f233d5cd..112a89bac4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2603,12 +2603,7 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000890, caniuse-lite@^1.0.30000892: - version "1.0.30000892" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000892.tgz#344d2b51ee3ff5977537da4aa449c90eec40b759" - integrity sha512-X9rxMaWZNbJB5qjkDqPtNv/yfViTeUL6ILk0QJNxLV3OhKC5Acn5vxsuUvllR6B48mog8lmS+whwHq/QIYSL9w== - -caniuse-lite@^1.0.30000893: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000890, caniuse-lite@^1.0.30000892, caniuse-lite@^1.0.30000893: version "1.0.30000893" resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000893.tgz#284b20932bd41b93e21626975f2050cb01561986" integrity sha512-kOddHcTEef+NgN/fs0zmX2brHTNATVOWMEIhlZHCuwQRtXobjSw9pAECc44Op4bTBcavRjkLaPrGomknH7+Jvg== @@ -3353,14 +3348,14 @@ cssesc@^1.0.1: integrity sha512-S2hzrpWvE6G/rW7i7IxJfWBYn27QWfOIncUW++8Rbo1VB5zsJDSVPcnI+Q8z7rhxT6/yZeLOCja4cZnghJrNGA== cssnano-preset-default@^4.0.2: - version "4.0.2" - resolved "https://registry.npmjs.org/cssnano-preset-default/-/cssnano-preset-default-4.0.2.tgz#1de3f27e73b7f0fbf87c1d7fd7a63ae980ac3774" - integrity sha512-zO9PeP84l1E4kbrdyF7NSLtA/JrJY1paX5FHy5+w/ziIXO2kDqDMfJ/mosXkaHHSa3RPiIY3eB6aEgwx3IiGqA== + version "4.0.3" + resolved "https://registry.npmjs.org/cssnano-preset-default/-/cssnano-preset-default-4.0.3.tgz#9bfd1b06d4aa3991ed958ad9b9ec25a179261705" + integrity sha512-RYxcuQhGGybn+4twdn/c/A6Ephq31znqbWMdtjWdyC84IcqnXxBuLue0iNxHhwUr+eNtaJU4pJX8ro9F7Crw5w== dependencies: css-declaration-sorter "^4.0.1" cssnano-util-raw-cache "^4.0.1" postcss "^7.0.0" - postcss-calc "^6.0.2" + postcss-calc "^7.0.0" postcss-colormin "^4.0.2" postcss-convert-values "^4.0.1" postcss-discard-comments "^4.0.1" @@ -3410,17 +3405,7 @@ cssnano-util-same-parent@^4.0.0: resolved "https://registry.npmjs.org/cssnano-util-same-parent/-/cssnano-util-same-parent-4.0.1.tgz#574082fb2859d2db433855835d9a8456ea18bbf3" integrity sha512-WcKx5OY+KoSIAxBW6UBBRay1U6vkYheCdjyVNDm85zt5K9mHoGOfsOsqIszfAqrQQFIIKgjh2+FDgIj/zsl21Q== -cssnano@^4.1.0: - version "4.1.4" - resolved "https://registry.npmjs.org/cssnano/-/cssnano-4.1.4.tgz#55b71e3d8f5451dd3edc7955673415c98795788f" - integrity sha512-wP0wbOM9oqsek14CiNRYrK9N3w3jgadtGZKHXysgC/OMVpy0KZgWVPdNqODSZbz7txO9Gekr9taOfcCgL0pOOw== - dependencies: - cosmiconfig "^5.0.0" - cssnano-preset-default "^4.0.2" - is-resolvable "^1.0.0" - postcss "^7.0.0" - -cssnano@^4.1.5: +cssnano@^4.1.0, cssnano@^4.1.5: version "4.1.5" resolved "https://registry.npmjs.org/cssnano/-/cssnano-4.1.5.tgz#cfe5ffa722079f339ac2a6d547d88dd8ac8a498d" integrity sha512-+6m3g8zV87VDIMCXpDzlaXyzo9h9VrIn9o/XRU6ufH/AddZw/mHzmmmNv83+MxpX5rnVbYPxuAMYPjuDgjd9Hw== @@ -6743,7 +6728,7 @@ memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1: meow@^3.3.0: version "3.7.0" - resolved "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" + resolved "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" integrity sha1-cstmi0JSKCkKu/qFaJJYcwioAfs= dependencies: camelcase-keys "^2.0.0" @@ -7882,15 +7867,15 @@ postcss-attribute-case-insensitive@^4.0.0: postcss "^7.0.2" postcss-selector-parser "^5.0.0-rc.3" -postcss-calc@^6.0.2: - version "6.0.2" - resolved "https://registry.npmjs.org/postcss-calc/-/postcss-calc-6.0.2.tgz#4d9a43e27dbbf27d095fecb021ac6896e2318337" - integrity sha512-fiznXjEN5T42Qm7qqMCVJXS3roaj9r4xsSi+meaBVe7CJBl8t/QLOXu02Z2E6oWAMWIvCuF6JrvzFekmVEbOKA== +postcss-calc@^7.0.0: + version "7.0.0" + resolved "https://registry.npmjs.org/postcss-calc/-/postcss-calc-7.0.0.tgz#cf0e78e1d7d9f75119b833abc786fa4b61afedda" + integrity sha512-o04XICBwDxXVYw1TXkzxs36WRgk9OECGiSUoyYMNoFWHLAQCKKeaqhrNBTUKdStMfwik3gSLLztHebTSV5kJOA== dependencies: css-unit-converter "^1.1.1" postcss "^7.0.2" - postcss-selector-parser "^2.2.2" - reduce-css-calc "^2.0.0" + postcss-selector-parser "^5.0.0-rc.3" + postcss-value-parser "^3.3.0" postcss-color-functional-notation@^2.0.1: version "2.0.1" @@ -8123,9 +8108,9 @@ postcss-media-minmax@^4.0.0: postcss "^7.0.2" postcss-merge-longhand@^4.0.6: - version "4.0.6" - resolved "https://registry.npmjs.org/postcss-merge-longhand/-/postcss-merge-longhand-4.0.6.tgz#2b938fa3529c3d1657e53dc7ff0fd604dbc85ff1" - integrity sha512-JavnI+V4IHWsaUAfOoKeMEiJQGXTraEy1nHM0ILlE6NIQPEZrJDAnPh3lNGZ5HAk2mSSrwp66JoGhvjp6SqShA== + version "4.0.7" + resolved "https://registry.npmjs.org/postcss-merge-longhand/-/postcss-merge-longhand-4.0.7.tgz#77430fa60e36745887c1c725ab3782c40f48363d" + integrity sha512-b2g9jC52xY0bwl8Dz1Xzfvn8x1KfmSQ0O8rc88hiv0bmYM6ky3xk1Zq128UClizM6SMBx0w7aqfrpS9u71d4Ow== dependencies: css-color-names "0.0.4" postcss "^7.0.0" @@ -8424,15 +8409,6 @@ postcss-selector-not@^4.0.0: balanced-match "^1.0.0" postcss "^7.0.2" -postcss-selector-parser@^2.2.2: - version "2.2.3" - resolved "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-2.2.3.tgz#f9437788606c3c9acee16ffe8d8b16297f27bb90" - integrity sha1-+UN3iGBsPJrO4W/+jYsWKX8nu5A= - dependencies: - flatten "^1.0.2" - indexes-of "^1.0.1" - uniq "^1.0.1" - postcss-selector-parser@^3.0.0, postcss-selector-parser@^3.1.1: version "3.1.1" resolved "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-3.1.1.tgz#4f875f4afb0c96573d5cf4d74011aee250a7e865" @@ -9057,14 +9033,6 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" -reduce-css-calc@^2.0.0: - version "2.1.5" - resolved "https://registry.npmjs.org/reduce-css-calc/-/reduce-css-calc-2.1.5.tgz#f283712f0c9708ef952d328f4b16112d57b03714" - integrity sha512-AybiBU03FKbjYzyvJvwkJZY6NLN+80Ufc2EqEs+41yQH+8wqBEslD6eGiS0oIeq5TNLA5PrhBeYHXWdn8gtW7A== - dependencies: - css-unit-converter "^1.1.1" - postcss-value-parser "^3.3.0" - regenerate-unicode-properties@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-7.0.0.tgz#107405afcc4a190ec5ed450ecaa00ed0cafa7a4c"