mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
perf(SSR): bundle with native async/await and less transpilations
This commit is contained in:
parent
e010114014
commit
afc874a11a
@ -128,19 +128,6 @@ export default class Builder {
|
||||
// Call before hook
|
||||
await this.nuxt.callHook('build:before', this, this.options.build)
|
||||
|
||||
// Babel options
|
||||
this.babelOptions = _.defaults(this.options.build.babel, {
|
||||
babelrc: false,
|
||||
cacheDirectory: !!this.options.dev
|
||||
})
|
||||
if (!this.babelOptions.babelrc && !this.babelOptions.presets) {
|
||||
this.babelOptions.presets = [
|
||||
[require.resolve('babel-preset-vue-app'), {
|
||||
targets: { ie: 9, uglify: true }
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
// Map postcss plugins into instances on object mode once
|
||||
if (isPureObject(this.options.build.postcss)) {
|
||||
if (isPureObject(this.options.build.postcss.plugins)) {
|
||||
@ -193,6 +180,30 @@ export default class Builder {
|
||||
return this
|
||||
}
|
||||
|
||||
getBabelOptions({ isServer }) {
|
||||
const options = _.defaults({}, {
|
||||
babelrc: false,
|
||||
cacheDirectory: !!this.options.dev
|
||||
}, this.options.build.babel)
|
||||
|
||||
if (typeof options.presets === 'function') {
|
||||
options.presets = options.presets({ isServer })
|
||||
}
|
||||
|
||||
if (!options.babelrc && !options.presets) {
|
||||
options.presets = [
|
||||
[
|
||||
require.resolve('babel-preset-vue-app'),
|
||||
{
|
||||
targets: isServer ? { node: '8.0.0' } : { ie: 9, uglify: true }
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
async generateRoutesAndFiles() {
|
||||
debug('Generating files...')
|
||||
// -- Templates --
|
||||
|
@ -14,7 +14,7 @@ import WarnFixPlugin from './warnfix-plugin'
|
||||
| webpack config files
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
export default function webpackBaseConfig(name) {
|
||||
export default function webpackBaseConfig({ name, isServer }) {
|
||||
const nodeModulesDir = join(__dirname, '..', 'node_modules')
|
||||
|
||||
const config = {
|
||||
@ -65,13 +65,13 @@ export default function webpackBaseConfig(name) {
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader',
|
||||
options: this.vueLoader()
|
||||
options: this.vueLoader({ isServer })
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
options: Object.assign({}, this.babelOptions)
|
||||
options: this.getBabelOptions({ isServer })
|
||||
},
|
||||
{ test: /\.css$/, use: this.styleLoader('css') },
|
||||
{ test: /\.less$/, use: this.styleLoader('less', 'less-loader') },
|
||||
|
@ -25,7 +25,7 @@ debug.color = 2 // Force green color
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
export default function webpackClientConfig() {
|
||||
let config = base.call(this, 'client')
|
||||
let config = base.call(this, { name: 'client', isServer: false })
|
||||
|
||||
// Entry points
|
||||
config.entry.app = resolve(this.options.buildDir, 'client.js')
|
||||
|
@ -12,7 +12,7 @@ import base from './base.config.js'
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
export default function webpackServerConfig() {
|
||||
let config = base.call(this, 'server')
|
||||
let config = base.call(this, { name: 'server', isServer: true })
|
||||
|
||||
// env object defined in nuxt.config.js
|
||||
let env = {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default function vueLoader() {
|
||||
export default function vueLoader({ isServer }) {
|
||||
// https://vue-loader.vuejs.org/en
|
||||
const config = {
|
||||
postcss: this.options.build.postcss,
|
||||
@ -8,7 +8,7 @@ export default function vueLoader() {
|
||||
loaders: {
|
||||
'js': {
|
||||
loader: 'babel-loader',
|
||||
options: Object.assign({}, this.babelOptions)
|
||||
options: this.getBabelOptions({ isServer })
|
||||
},
|
||||
// Note: do not nest the `postcss` option under `loaders`
|
||||
'css': this.styleLoader('css', [], true),
|
||||
|
Loading…
Reference in New Issue
Block a user