From 471a32a1a8380306a0a5a681978b5cc6fda3093c Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Wed, 2 Jan 2019 22:30:19 +0100 Subject: [PATCH] feat: add styleExtensions (#4671) --- packages/config/src/config/_common.js | 1 + packages/core/src/resolver.js | 6 ++++-- packages/vue-app/template/App.js | 2 +- test/fixtures/with-config/nuxt.config.js | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/config/src/config/_common.js b/packages/config/src/config/_common.js index 531589473a..0cc0464871 100644 --- a/packages/config/src/config/_common.js +++ b/packages/config/src/config/_common.js @@ -42,6 +42,7 @@ export default () => ({ store: 'store' }, extensions: [], + styleExtensions: ['css', 'pcss', 'postcss', 'styl', 'stylus', 'scss', 'sass', 'less'], // Ignores ignorePrefix: '-', diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index 9b41386f4e..7dc898379c 100644 --- a/packages/core/src/resolver.js +++ b/packages/core/src/resolver.js @@ -46,7 +46,7 @@ export default class Resolver { return resolve(this.options.srcDir, path) } - resolvePath(path, { alias, module } = {}) { + resolvePath(path, { alias, module, isStyle } = {}) { // Fast return in case of path exists if (fs.existsSync(path)) { return path @@ -80,8 +80,10 @@ export default class Resolver { } } + const extensions = isStyle ? this.options.styleExtensions : this.options.extensions + // Check if any resolvedPath.[ext] or resolvedPath/index.[ext] exists - for (const ext of this.options.extensions) { + for (const ext of extensions) { if (!isDirectory && fs.existsSync(resolvedPath + '.' + ext)) { return resolvedPath + '.' + ext } diff --git a/packages/vue-app/template/App.js b/packages/vue-app/template/App.js index 633e0b72f5..d14d7a8ed5 100644 --- a/packages/vue-app/template/App.js +++ b/packages/vue-app/template/App.js @@ -1,7 +1,7 @@ import Vue from 'vue' <% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %> <% css.forEach((c) => { %> -import '<%= relativeToBuild(resolvePath(c.src || c)) %>' +import '<%= relativeToBuild(resolvePath(c.src || c, { isStyle: true })) %>' <% }) %> <%= Object.keys(layouts).map((key) => { diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 95f39ec4c8..a73b7ffed5 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -80,7 +80,7 @@ export default { }) } }, - css: [{ src: '~/assets/app.pcss' }], + css: [{ src: '~/assets/app' }], render: { csp: true, http2: {