mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +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)
|
// Prioritize nested node_modules in webpack search path (#2558)
|
||||||
const webpackModulesDir = ['node_modules'].concat(this.options.modulesDir)
|
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 = {
|
const config = {
|
||||||
name,
|
name,
|
||||||
entry: {
|
entry: {
|
||||||
@ -39,16 +45,13 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.json', '.vue', '.jsx'],
|
extensions: ['.js', '.json', '.vue', '.jsx'],
|
||||||
alias: {
|
alias: Object.assign({
|
||||||
'~': join(this.options.srcDir),
|
'~': join(this.options.srcDir),
|
||||||
'~~': join(this.options.rootDir),
|
'~~': join(this.options.rootDir),
|
||||||
'@': join(this.options.srcDir),
|
'@': join(this.options.srcDir),
|
||||||
'@@': join(this.options.rootDir),
|
'@@': 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')
|
static: join(this.options.srcDir, 'static')
|
||||||
},
|
}, assetsAlias),
|
||||||
modules: webpackModulesDir
|
modules: webpackModulesDir
|
||||||
},
|
},
|
||||||
resolveLoader: {
|
resolveLoader: {
|
||||||
|
@ -56,16 +56,18 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
|
|||||||
|
|
||||||
// css-loader
|
// css-loader
|
||||||
// https://github.com/webpack-contrib/css-loader
|
// https://github.com/webpack-contrib/css-loader
|
||||||
|
const assetsAlias = {}
|
||||||
|
assetsAlias[`/${this.options.assetsDir}`] = join(this.options.srcDir, this.options.assetsDir)
|
||||||
|
|
||||||
loaders.unshift({
|
loaders.unshift({
|
||||||
loader: 'css-loader',
|
loader: 'css-loader',
|
||||||
options: {
|
options: {
|
||||||
sourceMap,
|
sourceMap,
|
||||||
minimize: !this.options.dev,
|
minimize: !this.options.dev,
|
||||||
importLoaders: loaders.length, // Important!
|
importLoaders: loaders.length, // Important!
|
||||||
alias: {
|
alias: Object.assign({
|
||||||
'/static': join(this.options.srcDir, 'static'),
|
'/static': join(this.options.srcDir, 'static')
|
||||||
'/assets': join(this.options.srcDir, 'assets')
|
}, assetsAlias)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -284,6 +284,7 @@ Options.defaults = {
|
|||||||
name: 'layout',
|
name: 'layout',
|
||||||
mode: 'out-in'
|
mode: 'out-in'
|
||||||
},
|
},
|
||||||
|
assetsDir: 'assets',
|
||||||
pagesDir: 'pages',
|
pagesDir: 'pages',
|
||||||
router: {
|
router: {
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
|
Loading…
Reference in New Issue
Block a user