perf(builder): experimental thread-loader and cache-loader

This commit is contained in:
Pooya Parsa 2018-03-23 01:51:17 +04:30
parent 7e308f9340
commit 88bab354b0
4 changed files with 70 additions and 9 deletions

View File

@ -99,10 +99,37 @@ export default class WebpackBaseConfig {
} }
} }
perfLoaders(_baseLoaders) {
if (this.options.dev) {
return _baseLoaders
}
const loaders = []
if (this.options.build.cache) {
// https://github.com/webpack-contrib/cache-loader
loaders.push({
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve('node_modules/.cache/cache-loader')
}
})
}
if (this.options.build.parallel) {
// https://github.com/webpack-contrib/thread-loader
loaders.push({
loader: 'thread-loader',
options: {}
})
}
return loaders.concat(_baseLoaders)
}
rules() { rules() {
const styleLoader = createStyleLoader({ const styleLoader = createStyleLoader({ isServer: this.isServer })
isServer: this.isServer
})
return [ return [
{ {
test: /\.vue$/, test: /\.vue$/,
@ -111,12 +138,20 @@ export default class WebpackBaseConfig {
}, },
{ {
test: /\.jsx?$/, test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/, exclude: /node_modules/,
options: this.getBabelOptions() use: this.perfLoaders({
loader: 'babel-loader',
options: this.getBabelOptions()
})
},
{
test: /\.css$/,
use: styleLoader.call(this.builder, 'css')
},
{
test: /\.less$/,
use: styleLoader.call(this.builder, 'less', 'less-loader')
}, },
{ test: /\.css$/, use: styleLoader.call(this.builder, 'css') },
{ test: /\.less$/, use: styleLoader.call(this.builder, 'less', 'less-loader') },
{ {
test: /\.sass$/, test: /\.sass$/,
use: styleLoader.call(this.builder, 'sass', { use: styleLoader.call(this.builder, 'sass', {
@ -124,7 +159,10 @@ export default class WebpackBaseConfig {
options: { indentedSyntax: true } options: { indentedSyntax: true }
}) })
}, },
{ test: /\.scss$/, use: styleLoader.call(this.builder, 'scss', 'sass-loader') }, {
test: /\.scss$/,
use: styleLoader.call(this.builder, 'scss', 'sass-loader')
},
{ {
test: /\.styl(us)?$/, test: /\.styl(us)?$/,
use: styleLoader.call(this.builder, 'stylus', 'stylus-loader') use: styleLoader.call(this.builder, 'stylus', 'stylus-loader')

View File

@ -1,4 +1,6 @@
import path from 'path' import path from 'path'
import os from 'os'
import isCI from 'is-ci' import isCI from 'is-ci'
export default { export default {
@ -35,6 +37,8 @@ export default {
extractCSS: false, extractCSS: false,
cssSourceMap: undefined, cssSourceMap: undefined,
ssr: undefined, ssr: undefined,
parallel: os.cpus().length > 1,
cache: true,
publicPath: '/_nuxt/', publicPath: '/_nuxt/',
filenames: { filenames: {
app: '[name].[chunkhash].js', app: '[name].[chunkhash].js',

View File

@ -62,6 +62,7 @@
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
"babel-loader": "^7.1.4", "babel-loader": "^7.1.4",
"babel-preset-vue-app": "^2.0.0", "babel-preset-vue-app": "^2.0.0",
"cache-loader": "^1.2.2",
"chalk": "^2.3.2", "chalk": "^2.3.2",
"chokidar": "^2.0.1", "chokidar": "^2.0.1",
"compression": "^1.7.1", "compression": "^1.7.1",
@ -101,6 +102,7 @@
"server-destroy": "^1.0.1", "server-destroy": "^1.0.1",
"source-map": "^0.7.2", "source-map": "^0.7.2",
"style-resources-loader": "^1.1.0", "style-resources-loader": "^1.1.0",
"thread-loader": "^1.1.5",
"time-fix-plugin": "^2.0.0", "time-fix-plugin": "^2.0.0",
"uglifyjs-webpack-plugin": "^1.2.4", "uglifyjs-webpack-plugin": "^1.2.4",
"upath": "^1.0.2", "upath": "^1.0.2",

View File

@ -398,7 +398,7 @@ async@^1.4.0:
version "1.5.2" version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@^2.1.4: async@^2.1.4, async@^2.3.0:
version "2.6.0" version "2.6.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.0.tgz#61a29abb6fcc026fea77e56d1c6ec53a795951f4" resolved "https://registry.yarnpkg.com/async/-/async-2.6.0.tgz#61a29abb6fcc026fea77e56d1c6ec53a795951f4"
dependencies: dependencies:
@ -1322,6 +1322,15 @@ cache-base@^1.0.1:
union-value "^1.0.0" union-value "^1.0.0"
unset-value "^1.0.0" unset-value "^1.0.0"
cache-loader@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/cache-loader/-/cache-loader-1.2.2.tgz#6d5c38ded959a09cc5d58190ab5af6f73bd353f5"
dependencies:
loader-utils "^1.1.0"
mkdirp "^0.5.1"
neo-async "^2.5.0"
schema-utils "^0.4.2"
caller-path@^0.1.0: caller-path@^0.1.0:
version "0.1.0" version "0.1.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
@ -6960,6 +6969,14 @@ text-table@~0.2.0:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
thread-loader@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/thread-loader/-/thread-loader-1.1.5.tgz#7f9d6701f773734fff1832586779021ab8571917"
dependencies:
async "^2.3.0"
loader-runner "^2.3.0"
loader-utils "^1.1.0"
throat@4.1.0, throat@^4.0.0: throat@4.1.0, throat@^4.0.0:
version "4.1.0" version "4.1.0"
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a" resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"