From 23c11b1cef6e2e4aa390f38689c141ca7d9ed74c Mon Sep 17 00:00:00 2001
From: Pooya Parsa <pooya@pi0.ir>
Date: Thu, 1 Mar 2018 10:42:48 +0330
Subject: [PATCH] remove dll support

webpack 4 is more faster and dll is
 problematic and unstable.
---
 lib/builder/builder.js               | 33 ++---------------
 lib/builder/webpack/client.config.js | 30 ----------------
 lib/builder/webpack/dll.config.js    | 46 ------------------------
 lib/common/options.js                |  5 +--
 test/dll.test.js                     | 53 ----------------------------
 test/fixtures/dll/nuxt.config.js     | 15 --------
 test/fixtures/dll/pages/index.vue    |  0
 7 files changed, 3 insertions(+), 179 deletions(-)
 delete mode 100644 lib/builder/webpack/dll.config.js
 delete mode 100644 test/dll.test.js
 delete mode 100644 test/fixtures/dll/nuxt.config.js
 delete mode 100644 test/fixtures/dll/pages/index.vue

diff --git a/lib/builder/builder.js b/lib/builder/builder.js
index bf85d8906c..d40ba1c57d 100644
--- a/lib/builder/builder.js
+++ b/lib/builder/builder.js
@@ -23,7 +23,6 @@ const {
 const { Options } = require('../common')
 const clientWebpackConfig = require('./webpack/client.config.js')
 const serverWebpackConfig = require('./webpack/server.config.js')
-const dllWebpackConfig = require('./webpack/dll.config.js')
 const upath = require('upath')
 
 const debug = Debug('nuxt:build')
@@ -95,21 +94,6 @@ module.exports = class Builder {
       .filter(v => v)
   }
 
-  vendorEntries() {
-    // Used for dll
-    const vendor = this.vendor()
-    const vendorEntries = {}
-    vendor.forEach(v => {
-      try {
-        require.resolve(v)
-        vendorEntries[v] = [v]
-      } catch (e) {
-        // Ignore
-      }
-    })
-    return vendorEntries
-  }
-
   forGenerate() {
     this.isStatic = true
   }
@@ -510,11 +494,6 @@ module.exports = class Builder {
       }
     })
 
-    // Make a dll plugin after compile to make nuxt dev builds faster
-    if (this.options.build.dll && this.options.dev) {
-      compilersOptions.push(dllWebpackConfig.call(this, clientConfig))
-    }
-
     // Initialize shared FS and Cache
     const sharedFS = this.options.dev && new MFS()
     const sharedCache = {}
@@ -522,8 +501,8 @@ module.exports = class Builder {
     // Initialize compilers
     this.compilers = compilersOptions.map(compilersOption => {
       const compiler = webpack(compilersOption)
-      // In dev, write files in memory FS (except for DLL)
-      if (sharedFS && !compiler.name.includes('-dll')) {
+      // In dev, write files in memory FS
+      if (sharedFS) {
         compiler.outputFileSystem = sharedFS
       }
       compiler.cache = sharedCache
@@ -556,14 +535,6 @@ module.exports = class Builder {
             if (compiler.options.name === 'client') {
               return this.webpackDev(compiler)
             }
-            // DLL build, should run only once
-            if (compiler.options.name.includes('-dll')) {
-              compiler.run((err, stats) => {
-                if (err) return reject(err)
-                debug('[DLL] updated')
-              })
-              return
-            }
             // Server, build and watch for changes
             this.compilersWatching.push(
               compiler.watch(this.options.watchers.webpack, err => {
diff --git a/lib/builder/webpack/client.config.js b/lib/builder/webpack/client.config.js
index 77988054f4..b2522fc133 100644
--- a/lib/builder/webpack/client.config.js
+++ b/lib/builder/webpack/client.config.js
@@ -127,11 +127,6 @@ module.exports = function webpackClientConfig() {
 
     // HMR
     config.plugins.push(new webpack.HotModuleReplacementPlugin())
-
-    // DllReferencePlugin
-    if (this.options.build.dll) {
-      dllPlugin.call(this, config)
-    }
   }
 
   // --------------------------------------
@@ -204,28 +199,3 @@ module.exports = function webpackClientConfig() {
 
   return config
 }
-
-// --------------------------------------------------------------------------
-// Adds DLL plugin
-// https://github.com/webpack/webpack/tree/master/examples/dll-user
-// --------------------------------------------------------------------------
-function dllPlugin(config) {
-  const _dlls = []
-  const vendorEntries = this.vendorEntries()
-  const dllDir = resolve(this.options.cacheDir, config.name + '-dll')
-  Object.keys(vendorEntries).forEach(v => {
-    const dllManifestFile = resolve(dllDir, v + '-manifest.json')
-    if (existsSync(dllManifestFile)) {
-      _dlls.push(v)
-      config.plugins.push(
-        new webpack.DllReferencePlugin({
-          // context: this.options.rootDir,
-          manifest: dllManifestFile // Using full path to allow finding .js dll file
-        })
-      )
-    }
-  })
-  if (_dlls.length) {
-    debug('Using dll for ' + _dlls.join(','))
-  }
-}
diff --git a/lib/builder/webpack/dll.config.js b/lib/builder/webpack/dll.config.js
deleted file mode 100644
index 5ad19116b3..0000000000
--- a/lib/builder/webpack/dll.config.js
+++ /dev/null
@@ -1,46 +0,0 @@
-const webpack = require('webpack')
-const { resolve } = require('path')
-const ClientConfig = require('./client.config')
-
-/*
-|--------------------------------------------------------------------------
-| Webpack Dll Config
-| https://github.com/webpack/webpack/tree/master/examples/dll
-|--------------------------------------------------------------------------
-*/
-module.exports = function webpackDllConfig(_refConfig) {
-  const refConfig = _refConfig || new ClientConfig()
-
-  const name = refConfig.name + '-dll'
-  const dllDir = resolve(this.options.cacheDir, name)
-
-  let config = {
-    name,
-    entry: this.vendorEntries(),
-    // context: this.options.rootDir,
-    resolve: refConfig.resolve,
-    target: refConfig.target,
-    resolveLoader: refConfig.resolveLoader,
-    module: refConfig.module,
-    plugins: []
-  }
-
-  config.output = {
-    path: dllDir,
-    filename: '[name]_[hash].js',
-    library: '[name]_[hash]'
-  }
-
-  config.plugins.push(
-    new webpack.DllPlugin({
-      // The path to the manifest file which maps between
-      // modules included in a bundle and the internal IDs
-      // within that bundle
-      path: resolve(dllDir, '[name]-manifest.json'),
-
-      name: '[name]_[hash]'
-    })
-  )
-
-  return config
-}
diff --git a/lib/common/options.js b/lib/common/options.js
index d8a08d3ef0..03d31b874b 100644
--- a/lib/common/options.js
+++ b/lib/common/options.js
@@ -187,7 +187,6 @@ Options.defaults = {
   build: {
     analyze: false,
     profile: process.argv.includes('--profile'),
-    dll: false,
     maxChunkSize: false,
     extractCSS: false,
     cssSourceMap: undefined,
@@ -329,9 +328,7 @@ Options.defaults = {
     }
   },
   watchers: {
-    webpack: {
-      ignored: /-dll/
-    },
+    webpack: {},
     chokidar: {}
   },
   editor: undefined,
diff --git a/test/dll.test.js b/test/dll.test.js
deleted file mode 100644
index db58520547..0000000000
--- a/test/dll.test.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import { promisify } from 'util'
-import test from 'ava'
-import { resolve } from 'path'
-import fs from 'fs'
-import { Nuxt, Builder } from '..'
-import { interceptLog, release } from './helpers/console'
-
-const readFile = promisify(fs.readFile)
-const rootDir = resolve(__dirname, 'fixtures/dll')
-const dllDir = resolve(rootDir, '.cache/client-dll')
-
-const checkCache = lib => {
-  return async t => {
-    const manifest = await readFile(
-      resolve(dllDir, `./${lib}-manifest.json`),
-      'utf-8'
-    )
-    t.truthy(JSON.parse(manifest).name)
-    t.true(fs.existsSync(resolve(dllDir, `./${JSON.parse(manifest).name}.js`)))
-  }
-}
-
-let nuxt
-
-test.serial('Init Nuxt.js', async t => {
-  let config = require(resolve(rootDir, 'nuxt.config.js'))
-  config.rootDir = rootDir
-  config.dev = true
-
-  const logSpy = await interceptLog(async () => {
-    nuxt = new Nuxt(config)
-    await new Builder(nuxt).build()
-  })
-  t.true(logSpy.calledWithMatch('DONE'))
-})
-
-test('Check vue cache', checkCache('vue'))
-
-test('Check vue-meta cache', checkCache('vue-meta'))
-
-test('Check vue-router cache', checkCache('vue-router'))
-
-test('Build with DllReferencePlugin', async t => {
-  const logSpy = await interceptLog()
-  await new Builder(nuxt).build()
-  release()
-  t.true(logSpy.withArgs('Using dll for 3 libs').calledOnce)
-})
-
-// Close server and ask nuxt to stop listening to file changes
-test.after.always('Closing nuxt.js', t => {
-  nuxt.close()
-})
diff --git a/test/fixtures/dll/nuxt.config.js b/test/fixtures/dll/nuxt.config.js
deleted file mode 100644
index c87dc601f3..0000000000
--- a/test/fixtures/dll/nuxt.config.js
+++ /dev/null
@@ -1,15 +0,0 @@
-module.exports = {
-  build: {
-    stats: false,
-    dll: true,
-    extend(config, options) {
-      if (options.isClient) {
-        const dlls = config.plugins.filter(
-          plugin => plugin.constructor.name === 'DllReferencePlugin'
-        )
-        console.log('Using dll for ' + dlls.length + ' libs') // eslint-disable-line no-console
-      }
-      return config
-    }
-  }
-}
diff --git a/test/fixtures/dll/pages/index.vue b/test/fixtures/dll/pages/index.vue
deleted file mode 100644
index e69de29bb2..0000000000