mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat: custom assets directory
This commit is contained in:
parent
225021571a
commit
fb29df43fd
@ -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: {
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -284,6 +284,7 @@ Options.defaults = {
|
||||
name: 'layout',
|
||||
mode: 'out-in'
|
||||
},
|
||||
assetsDir: 'assets',
|
||||
pagesDir: 'pages',
|
||||
router: {
|
||||
mode: 'history',
|
||||
|
Loading…
Reference in New Issue
Block a user