feat: custom assets directory

This commit is contained in:
Ricardo Gobbo de Souza 2018-02-03 09:10:06 -02:00
parent 225021571a
commit fb29df43fd
3 changed files with 15 additions and 9 deletions

View File

@ -19,6 +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 = {}
// Used by vue-loader so we can use in templates
// with <img src="~/assets/nuxt.png"/>
assetsAlias[this.options.assetsDir] = join(this.options.srcDir, this.options.assetsDir)
const config = {
name,
entry: {
@ -39,16 +45,13 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
},
resolve: {
extensions: ['.js', '.json', '.vue', '.jsx'],
alias: {
alias: Object.assign({
'~': join(this.options.srcDir),
'~~': join(this.options.rootDir),
'@': join(this.options.srcDir),
'@@': join(this.options.rootDir),
// Used by vue-loader so we can use in templates
// with <img src="~/assets/nuxt.png"/>
assets: join(this.options.srcDir, 'assets'),
static: join(this.options.srcDir, 'static')
},
}, assetsAlias),
modules: webpackModulesDir
},
resolveLoader: {

View File

@ -56,16 +56,18 @@ 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)
loaders.unshift({
loader: 'css-loader',
options: {
sourceMap,
minimize: !this.options.dev,
importLoaders: loaders.length, // Important!
alias: {
'/static': join(this.options.srcDir, 'static'),
'/assets': join(this.options.srcDir, 'assets')
}
alias: Object.assign({
'/static': join(this.options.srcDir, 'static')
}, assetsAlias)
}
})

View File

@ -284,6 +284,7 @@ Options.defaults = {
name: 'layout',
mode: 'out-in'
},
assetsDir: 'assets',
pagesDir: 'pages',
router: {
mode: 'history',