remove dll support

webpack 4 is more faster and dll is
 problematic and unstable.
This commit is contained in:
Pooya Parsa 2018-03-01 10:42:48 +03:30
parent 11280681d1
commit 23c11b1cef
7 changed files with 3 additions and 179 deletions

View File

@ -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 => {

View File

@ -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(','))
}
}

View File

@ -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
}

View File

@ -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,

View File

@ -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()
})

View File

@ -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
}
}
}

View File