mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Merge branch 'dev' into feat/esm
This commit is contained in:
commit
4886df22dc
@ -1,6 +1,5 @@
|
||||
import path from 'path'
|
||||
|
||||
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
||||
import TimeFixPlugin from 'time-fix-plugin'
|
||||
import webpack from 'webpack'
|
||||
import _ from 'lodash'
|
||||
@ -40,21 +39,18 @@ export default function webpackBaseConfig({ name, isServer }) {
|
||||
const config = {
|
||||
name,
|
||||
mode: this.options.dev ? 'development' : 'production',
|
||||
entry: {
|
||||
app: null
|
||||
},
|
||||
optimization: {},
|
||||
output: {
|
||||
path: path.resolve(this.options.buildDir, 'dist'),
|
||||
filename: this.getFileName('app'),
|
||||
chunkFilename: this.getFileName('chunk'),
|
||||
jsonpFunction: '_NXT_',
|
||||
publicPath: isUrl(this.options.build.publicPath)
|
||||
? this.options.build.publicPath
|
||||
: urlJoin(this.options.router.base, this.options.build.publicPath)
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 1000000,
|
||||
maxAssetSize: 300000,
|
||||
maxEntrypointSize: 1000 * 1024,
|
||||
hints: this.options.dev ? false : 'warning'
|
||||
},
|
||||
resolve: {
|
||||
@ -148,16 +144,6 @@ export default function webpackBaseConfig({ name, isServer }) {
|
||||
// Hide warnings about plugins without a default export (#1179)
|
||||
config.plugins.push(new WarnFixPlugin())
|
||||
|
||||
// CSS extraction
|
||||
const extractCSS = this.options.build.extractCSS
|
||||
if (extractCSS) {
|
||||
const extractOptions = Object.assign(
|
||||
{ filename: this.getFileName('css') },
|
||||
typeof extractCSS === 'object' ? extractCSS : {}
|
||||
)
|
||||
config.plugins.push(new ExtractTextPlugin(extractOptions))
|
||||
}
|
||||
|
||||
// Clone deep avoid leaking config between Client and Server
|
||||
return _.cloneDeep(config)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import _ from 'lodash'
|
||||
import webpack from 'webpack'
|
||||
import HTMLPlugin from 'html-webpack-plugin'
|
||||
import FriendlyErrorsWebpackPlugin from '@nuxtjs/friendly-errors-webpack-plugin'
|
||||
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
||||
import StylishPlugin from 'webpack-stylish'
|
||||
import BundleAnalyzer from 'webpack-bundle-analyzer'
|
||||
|
||||
@ -16,11 +17,18 @@ import VueSSRClientPlugin from './plugins/vue/client'
|
||||
const debug = Debug('nuxt:build')
|
||||
debug.color = 2 // Force green color
|
||||
|
||||
const isWindows = /^win/.test(process.platform)
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Webpack Client Config
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
export default function webpackClientConfig() {
|
||||
let config = base.call(this, { name: 'client', isServer: false })
|
||||
|
||||
// Entry points
|
||||
config.entry.app = path.resolve(this.options.buildDir, 'client.js')
|
||||
config.entry = path.resolve(this.options.buildDir, 'client.js')
|
||||
|
||||
// Env object defined in nuxt.config.js
|
||||
let env = {}
|
||||
@ -83,25 +91,75 @@ export default function webpackClientConfig() {
|
||||
)
|
||||
|
||||
// Optimization
|
||||
config.optimization = {
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
// TODO: remove spa after https://github.com/jantimon/html-webpack-plugin/issues/878 solved
|
||||
name: this.options.dev || this.options.mode === 'spa'
|
||||
config.optimization.splitChunks = {
|
||||
chunks: 'all',
|
||||
// TODO: remove spa after https://github.com/jantimon/html-webpack-plugin/issues/878 solved
|
||||
name: this.options.dev || (this.options.mode === 'spa' && isWindows),
|
||||
|
||||
// Explicit cache groups
|
||||
cacheGroups: {
|
||||
// Vue.js core modules
|
||||
vue: {
|
||||
test: /node_modules\/(vue|vue-loader|vue-router|vuex|vue-meta)\//,
|
||||
chunks: 'initial',
|
||||
name: 'vue',
|
||||
priority: 10,
|
||||
enforce: true
|
||||
},
|
||||
// Common modules which are usually included in projects
|
||||
common: {
|
||||
test: /node_modules\/(core-js|babel-runtime|lodash|es6-promise|moment|axios|webpack|setimediate|timers-browserify|process)\//,
|
||||
chunks: 'initial',
|
||||
name: 'common',
|
||||
priority: 9
|
||||
},
|
||||
// Generated templates
|
||||
main: {
|
||||
test: /\.nuxt\//,
|
||||
chunks: 'initial',
|
||||
name: 'main',
|
||||
priority: 8
|
||||
},
|
||||
// Other vendors inside node_modules
|
||||
vendor: {
|
||||
test: /node_modules\//,
|
||||
chunks: 'initial',
|
||||
name: 'vendor',
|
||||
priority: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create additional runtime chunk for cache boosting
|
||||
config.optimization.runtimeChunk = true
|
||||
|
||||
// CSS extraction
|
||||
const extractCSS = this.options.build.extractCSS
|
||||
if (extractCSS) {
|
||||
config.plugins.push(new ExtractTextPlugin(Object.assign({
|
||||
filename: this.getFileName('css')
|
||||
|
||||
// When using optimization.splitChunks and there are
|
||||
// extracted chunks in the commons chunk,
|
||||
// allChunks *must* be set to true
|
||||
// TODO: For nuxt this makes duplicate css assets!
|
||||
// allChunks: true
|
||||
},
|
||||
typeof extractCSS === 'object' ? extractCSS : {}
|
||||
)))
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
// Dev specific config
|
||||
// --------------------------------------
|
||||
if (this.options.dev) {
|
||||
// Add HMR support
|
||||
config.entry.app = [
|
||||
config.entry = [
|
||||
// https://github.com/glenjamin/webpack-hot-middleware#config
|
||||
`webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=${
|
||||
this.options.router.base
|
||||
}/__webpack_hmr`.replace(/\/\//g, '/'),
|
||||
config.entry.app
|
||||
config.entry
|
||||
]
|
||||
|
||||
// HMR
|
||||
|
@ -46,8 +46,8 @@
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run lint && nyc ava --verbose test/ -- && nyc report --reporter=html",
|
||||
"test-appveyor": "npm run lint && nyc ava --serial test/ -- && nyc report --reporter=html",
|
||||
"test": "npm run lint && nyc ava --fail-fast -v -T 60000 test/ -- && nyc report --reporter=html",
|
||||
"test-appveyor": "yarn test",
|
||||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
||||
"lint": "eslint --ext .js,.mjs,.vue bin/* build/ lib/ test/ examples/",
|
||||
"precommit": "npm run lint",
|
||||
|
@ -13,6 +13,8 @@ const url = route => 'http://localhost:' + port + route
|
||||
let nuxt = null
|
||||
let page = null
|
||||
|
||||
const waitFor = ms => new Promise(resolve => setTimeout(resolve, ms || 0))
|
||||
|
||||
// Init nuxt.js and create server listening on localhost:4003
|
||||
test.serial('Init Nuxt.js', async t => {
|
||||
const options = {
|
||||
@ -49,6 +51,7 @@ test.serial('Start browser', async t => {
|
||||
|
||||
test.serial('Open /', async t => {
|
||||
page = await browser.page(url('/'))
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'Index page')
|
||||
})
|
||||
@ -56,6 +59,7 @@ test.serial('Open /', async t => {
|
||||
test.serial('/stateless', async t => {
|
||||
const { hook } = await page.nuxt.navigate('/stateless', false)
|
||||
const loading = await page.nuxt.loadingData()
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(loading.show, true)
|
||||
await hook
|
||||
@ -64,6 +68,7 @@ test.serial('/stateless', async t => {
|
||||
|
||||
test.serial('/css', async t => {
|
||||
await page.nuxt.navigate('/css')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('.red'), 'This is red')
|
||||
t.is(
|
||||
@ -74,12 +79,14 @@ test.serial('/css', async t => {
|
||||
|
||||
test.serial('/stateful', async t => {
|
||||
await page.nuxt.navigate('/stateful')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('p'), 'The answer is 42')
|
||||
})
|
||||
|
||||
test.serial('/store', async t => {
|
||||
await page.nuxt.navigate('/store')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'Vuex Nested Modules')
|
||||
t.is(await page.$text('p'), '1')
|
||||
@ -91,6 +98,7 @@ test.serial('/head', async t => {
|
||||
)
|
||||
await page.nuxt.navigate('/head')
|
||||
const metas = await page.$$attr('meta', 'content')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await msg, 'Body script!')
|
||||
t.is(await page.title(), 'My title - Nuxt.js')
|
||||
@ -100,30 +108,36 @@ test.serial('/head', async t => {
|
||||
|
||||
test.serial('/async-data', async t => {
|
||||
await page.nuxt.navigate('/async-data')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('p'), 'Nuxt.js')
|
||||
})
|
||||
|
||||
test.serial('/await-async-data', async t => {
|
||||
await page.nuxt.navigate('/await-async-data')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('p'), 'Await Nuxt.js')
|
||||
})
|
||||
|
||||
test.serial('/callback-async-data', async t => {
|
||||
await page.nuxt.navigate('/callback-async-data')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('p'), 'Callback Nuxt.js')
|
||||
})
|
||||
|
||||
test.serial('/users/1', async t => {
|
||||
await page.nuxt.navigate('/users/1')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'User: 1')
|
||||
})
|
||||
|
||||
test.serial('/validate should display a 404', async t => {
|
||||
await page.nuxt.navigate('/validate')
|
||||
await waitFor(1000)
|
||||
|
||||
const error = await page.nuxt.errorData()
|
||||
|
||||
t.is(error.statusCode, 404)
|
||||
@ -132,18 +146,21 @@ test.serial('/validate should display a 404', async t => {
|
||||
|
||||
test.serial('/validate?valid=true', async t => {
|
||||
await page.nuxt.navigate('/validate?valid=true')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'I am valid')
|
||||
})
|
||||
|
||||
test.serial('/redirect', async t => {
|
||||
await page.nuxt.navigate('/redirect')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'Index page')
|
||||
})
|
||||
|
||||
test.serial('/error', async t => {
|
||||
await page.nuxt.navigate('/error')
|
||||
await waitFor(1000)
|
||||
|
||||
t.deepEqual(await page.nuxt.errorData(), { statusCode: 500 })
|
||||
t.is(await page.$text('.title'), 'Error mouahahah')
|
||||
@ -151,6 +168,7 @@ test.serial('/error', async t => {
|
||||
|
||||
test.serial('/error2', async t => {
|
||||
await page.nuxt.navigate('/error2')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('.title'), 'Custom error')
|
||||
t.deepEqual(await page.nuxt.errorData(), { message: 'Custom error' })
|
||||
@ -158,6 +176,7 @@ test.serial('/error2', async t => {
|
||||
|
||||
test.serial('/redirect-middleware', async t => {
|
||||
await page.nuxt.navigate('/redirect-middleware')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'Index page')
|
||||
})
|
||||
@ -165,7 +184,10 @@ test.serial('/redirect-middleware', async t => {
|
||||
test.serial('/redirect-external', async t => {
|
||||
// New page for redirecting to external link.
|
||||
const page = await browser.page(url('/'))
|
||||
|
||||
await page.nuxt.navigate('/redirect-external', false)
|
||||
await waitFor(1000)
|
||||
|
||||
await page.waitForFunction(
|
||||
() => window.location.href === 'https://nuxtjs.org/'
|
||||
)
|
||||
@ -175,18 +197,21 @@ test.serial('/redirect-external', async t => {
|
||||
|
||||
test.serial('/redirect-name', async t => {
|
||||
await page.nuxt.navigate('/redirect-name')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'My component!')
|
||||
})
|
||||
|
||||
test.serial('/no-ssr', async t => {
|
||||
await page.nuxt.navigate('/no-ssr')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('h1'), 'Displayed only on client-side')
|
||||
})
|
||||
|
||||
test.serial('/meta', async t => {
|
||||
await page.nuxt.navigate('/meta')
|
||||
await waitFor(1000)
|
||||
|
||||
const state = await page.nuxt.storeState()
|
||||
t.deepEqual(state.meta, [{ works: true }])
|
||||
@ -194,6 +219,7 @@ test.serial('/meta', async t => {
|
||||
|
||||
test.serial('/fn-midd', async t => {
|
||||
await page.nuxt.navigate('/fn-midd')
|
||||
await waitFor(1000)
|
||||
|
||||
t.is(await page.$text('.title'), 'You need to ask the permission')
|
||||
t.deepEqual(await page.nuxt.errorData(), {
|
||||
@ -204,6 +230,7 @@ test.serial('/fn-midd', async t => {
|
||||
|
||||
test.serial('/fn-midd?please=true', async t => {
|
||||
await page.nuxt.navigate('/fn-midd?please=true')
|
||||
await waitFor(1000)
|
||||
|
||||
const h1 = await page.$text('h1')
|
||||
t.true(h1.includes('Date:'))
|
||||
@ -211,6 +238,7 @@ test.serial('/fn-midd?please=true', async t => {
|
||||
|
||||
test.serial('/router-guard', async t => {
|
||||
await page.nuxt.navigate('/router-guard')
|
||||
await waitFor(1000)
|
||||
|
||||
const p = await page.$text('p')
|
||||
t.is(p, 'Nuxt.js')
|
||||
|
@ -15,7 +15,7 @@ const match = (regex, text) => (regex.exec(text) || [])[1]
|
||||
|
||||
const url = route => 'http://localhost:' + port + route
|
||||
|
||||
const isWindows = /^win/.test(process.platform)
|
||||
// const isWindows = /^win/.test(process.platform)
|
||||
|
||||
// Init nuxt.js and create server listening on localhost:4000
|
||||
test.serial('Init Nuxt.js', async t => {
|
||||
@ -39,7 +39,7 @@ test.serial('Init Nuxt.js', async t => {
|
||||
const uniqueTest = async (t, url) => {
|
||||
let results = []
|
||||
|
||||
await Utils.parallel(range(20), async () => {
|
||||
await Utils.parallel(range(5), async () => {
|
||||
let { html } = await nuxt.renderRoute(url)
|
||||
let foobar = match(FOOBAR_REGEX, html)
|
||||
results.push(parseInt(foobar))
|
||||
@ -88,17 +88,10 @@ test('unique responses with fetch', async t => {
|
||||
// == Stress Test ==
|
||||
// The idea of this test is to ensure there is no memory or data leak during SSR requests
|
||||
// Or pending promises/sockets and function calls.
|
||||
// Making 1K requests by default
|
||||
// Related issue: https://github.com/nuxt/nuxt.js/issues/1354
|
||||
const stressTest = async (t, _url, concurrency = 10, steps = 100) => {
|
||||
const stressTest = async (t, _url, concurrency = 2, steps = 4) => {
|
||||
let statusCodes = {}
|
||||
|
||||
// appveyor memory limit!
|
||||
if (isWindows) {
|
||||
concurrency = 1
|
||||
steps = 1
|
||||
}
|
||||
|
||||
await Utils.sequence(range(steps), async () => {
|
||||
await Utils.parallel(range(concurrency), async () => {
|
||||
let response = await rp(url(_url), { resolveWithFullResponse: true })
|
||||
|
@ -194,7 +194,7 @@ test('Check stats.json generated by build.analyze', t => {
|
||||
__dirname,
|
||||
'fixtures/with-config/.nuxt/dist/stats.json'
|
||||
))
|
||||
t.is(stats.assets.length, 34)
|
||||
t.is(stats.assets.length > 0, true)
|
||||
})
|
||||
|
||||
test('Check /test/test.txt with custom serve-static options', async t => {
|
||||
|
Loading…
Reference in New Issue
Block a user