diff --git a/lib/builder/generator.js b/lib/builder/generator.js
index d94d751048..f55c2e8479 100644
--- a/lib/builder/generator.js
+++ b/lib/builder/generator.js
@@ -27,7 +27,7 @@ module.exports = class Generator {
this.builder = builder
// Set variables
- this.staticRoutes = resolve(this.options.srcDir, 'static')
+ this.staticRoutes = resolve(this.options.srcDir, this.options.staticDir)
this.srcBuiltPath = resolve(this.options.buildDir, 'dist')
this.distPath = resolve(this.options.rootDir, this.options.generate.dir)
this.distNuxtPath = join(
diff --git a/lib/builder/webpack/base.config.js b/lib/builder/webpack/base.config.js
index 3436c6bc37..8650b3c5e3 100644
--- a/lib/builder/webpack/base.config.js
+++ b/lib/builder/webpack/base.config.js
@@ -19,11 +19,12 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
// Prioritize nested node_modules in webpack search path (#2558)
const webpackModulesDir = ['node_modules'].concat(this.options.modulesDir)
- const assetsAlias = {}
+ const configAlias = {}
// Used by vue-loader so we can use in templates
// with
- assetsAlias[this.options.assetsDir] = join(this.options.srcDir, this.options.assetsDir)
+ configAlias[this.options.assetsDir] = join(this.options.srcDir, this.options.assetsDir)
+ configAlias[this.options.staticDir] = join(this.options.srcDir, this.options.staticDir)
const config = {
name,
@@ -49,9 +50,8 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
'~': join(this.options.srcDir),
'~~': join(this.options.rootDir),
'@': join(this.options.srcDir),
- '@@': join(this.options.rootDir),
- static: join(this.options.srcDir, 'static')
- }, assetsAlias),
+ '@@': join(this.options.rootDir)
+ }, configAlias),
modules: webpackModulesDir
},
resolveLoader: {
diff --git a/lib/builder/webpack/style-loader.js b/lib/builder/webpack/style-loader.js
index eace185401..f832415593 100755
--- a/lib/builder/webpack/style-loader.js
+++ b/lib/builder/webpack/style-loader.js
@@ -56,8 +56,9 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
// css-loader
// https://github.com/webpack-contrib/css-loader
- const assetsAlias = {}
- assetsAlias[`/${this.options.assetsDir}`] = join(this.options.srcDir, this.options.assetsDir)
+ const cssLoaderAlias = {}
+ cssLoaderAlias[`/${this.options.assetsDir}`] = join(this.options.srcDir, this.options.assetsDir)
+ cssLoaderAlias[`/${this.options.staticDir}`] = join(this.options.srcDir, this.options.staticDir)
loaders.unshift({
loader: 'css-loader',
@@ -65,9 +66,7 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
sourceMap,
minimize: !this.options.dev,
importLoaders: loaders.length, // Important!
- alias: Object.assign({
- '/static': join(this.options.srcDir, 'static')
- }, assetsAlias)
+ alias: cssLoaderAlias
}
})
diff --git a/lib/common/options.js b/lib/common/options.js
index ef8dc26223..3e81743abd 100755
--- a/lib/common/options.js
+++ b/lib/common/options.js
@@ -286,6 +286,7 @@ Options.defaults = {
},
assetsDir: 'assets',
pagesDir: 'pages',
+ staticDir: 'static',
router: {
mode: 'history',
base: '/',
diff --git a/lib/core/renderer.js b/lib/core/renderer.js
index 234b2de1d8..7eac5b58bf 100644
--- a/lib/core/renderer.js
+++ b/lib/core/renderer.js
@@ -251,7 +251,7 @@ module.exports = class Renderer {
// For serving static/ files to /
this.useMiddleware(
serveStatic(
- resolve(this.options.srcDir, 'static'),
+ resolve(this.options.srcDir, this.options.staticDir),
this.options.render.static
)
)
diff --git a/test/custom-dirs.test.js b/test/custom-dirs.test.js
index cd311a6f1b..06bddab108 100644
--- a/test/custom-dirs.test.js
+++ b/test/custom-dirs.test.js
@@ -1,8 +1,12 @@
import test from 'ava'
import { resolve } from 'path'
+import rp from 'request-promise-native'
import { Nuxt, Builder } from '..'
import { interceptLog } from './helpers/console'
+const port = 4007
+const url = route => 'http://localhost:' + port + route
+
let nuxt = null
let builder = null
@@ -24,14 +28,21 @@ test.before('Init Nuxt.js', async t => {
t.true(logSpy.calledWithMatch('OPEN'))
})
+test('/ (custom assets directory)', async t => {
+ const { html } = await nuxt.renderRoute('/')
+ t.true(html.includes('.global-css-selector'))
+})
+
test('/ (custom pages directory)', async t => {
const { html } = await nuxt.renderRoute('/')
t.true(html.includes('