diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 31cc4cba09..9a1b35171a 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -304,7 +304,7 @@ export default class Builder { } else if (this._nuxtPages) { // If user defined a custom method to create routes // Use nuxt.js createRoutes bases on pages/ const files = {} - ;(await glob(`${this.options.dir.pages}/**/*.{vue,js}`, { + ; (await glob(`${this.options.dir.pages}/**/*.{vue,js}`, { cwd: this.options.srcDir, ignore: this.options.ignore })).forEach((f) => { diff --git a/packages/webpack/src/builder.js b/packages/webpack/src/builder.js index cb526ab95f..7ea5870922 100644 --- a/packages/webpack/src/builder.js +++ b/packages/webpack/src/builder.js @@ -1,18 +1,23 @@ import fs from 'fs' +import path from 'path' import pify from 'pify' import webpack from 'webpack' import MFS from 'memory-fs' +import Glob from 'glob' import webpackDevMiddleware from 'webpack-dev-middleware' import webpackHotMiddleware from 'webpack-hot-middleware' import consola from 'consola' import { parallel, - sequence + sequence, + wrapArray } from '@nuxt/common' import { ClientConfig, ServerConfig, PerfLoader } from './config' +const glob = pify(Glob) + export default class WebpackBuilder { constructor(context) { this.context = context @@ -60,6 +65,18 @@ export default class WebpackBuilder { } } + // Check styleResource existence + const styleResources = this.context.options.build.styleResources + Object.keys(styleResources).forEach(async (ext) => { + await Promise.all(wrapArray(styleResources[ext]).map(async (p) => { + const styleResourceFiles = await glob(path.resolve(this.context.options.rootDir, p)) + + if (!styleResourceFiles || styleResourceFiles.length === 0) { + throw new Error(`Style Resource not found: ${p}`) + } + })) + }) + // Configure compilers this.compilers = compilersOptions.map((compilersOption) => { const compiler = webpack(compilersOption) diff --git a/packages/webpack/src/config/utils/style-loader.js b/packages/webpack/src/config/utils/style-loader.js index fea6ff8917..cd94e29da1 100644 --- a/packages/webpack/src/config/utils/style-loader.js +++ b/packages/webpack/src/config/utils/style-loader.js @@ -1,3 +1,4 @@ +import path from 'path' import MiniCssExtractPlugin from 'mini-css-extract-plugin' import { wrapArray } from '@nuxt/common' @@ -11,6 +12,7 @@ export default class StyleLoader { this.srcDir = options.srcDir this.assetsDir = options.dir.assets this.staticDir = options.dir.static + this.rootDir = options.rootDir this.loaders = options.build.loaders this.extractCSS = options.build.extractCSS this.resources = options.build.styleResources @@ -31,7 +33,7 @@ export default class StyleLoader { // style-resources-loader // https://github.com/yenshih/style-resources-loader if (extResource) { - const patterns = wrapArray(extResource) + const patterns = wrapArray(extResource).map(p => path.resolve(this.rootDir, p)) return { loader: 'style-resources-loader', diff --git a/test/fixtures/missing-style-resource/nuxt.config.js b/test/fixtures/missing-style-resource/nuxt.config.js new file mode 100644 index 0000000000..44d2cebae8 --- /dev/null +++ b/test/fixtures/missing-style-resource/nuxt.config.js @@ -0,0 +1,5 @@ +export default { + styleResources: { + 'stylus': './nothinghere' + } +} diff --git a/test/fixtures/with-config/assets/pre-process.css b/test/fixtures/with-config/assets/pre-process.css new file mode 100644 index 0000000000..71bea2b0ad --- /dev/null +++ b/test/fixtures/with-config/assets/pre-process.css @@ -0,0 +1,3 @@ +.pre-process-selector { + color: red; +} diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index f176838454..f90a89e542 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -61,7 +61,7 @@ export default { logLevel: 'error' }, styleResources: { - scss: '~/assets/pre-process.scss' + css: './assets/pre-process.css' }, babel: { presets({ isServer }) { diff --git a/test/unit/nuxt.test.js b/test/unit/nuxt.test.js index 992ce269b4..0108e7c2e2 100644 --- a/test/unit/nuxt.test.js +++ b/test/unit/nuxt.test.js @@ -56,4 +56,16 @@ describe('nuxt', () => { expect(s.includes('Plugin not found')).toBe(true) }) }) + + test('Warn when styleResource isn\'t found', () => { + const nuxt = new Nuxt({ + dev: false, + rootDir: resolve(__dirname, '..', 'fixtures', 'missing-style-resource') + }) + + return new Builder(nuxt).build().catch((err) => { + const s = String(err) + expect(s.includes('Style Resource not found')).toBe(true) + }) + }) }) diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index bc8cb0ee0c..09bea055fc 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -36,6 +36,11 @@ describe('with-config', () => { )).toBe(true) }) + test('/ (styleResources styles inlined)', async () => { + const { html } = await nuxt.renderRoute('/') + expect(html).toContain('.pre-process-selector') + }) + test('/ (custom app.html)', async () => { const { html } = await nuxt.renderRoute('/') expect(html.includes('

Made by Nuxt.js team

')).toBe(true)