Skip to content

Commit 2ff8b5a

Browse files
author
Pooya Parsa
committed
fix css-loader to handle ~/ aliases
nuxt#1241
1 parent 15f9994 commit 2ff8b5a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/builder/webpack/helpers.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
import ExtractTextPlugin from 'extract-text-webpack-plugin'
2+
import { join } from 'path'
23

34
export function extractStyles () {
45
return !this.options.dev && this.options.build.extractCSS
56
}
67

7-
export function styleLoader (ext, loader = []) {
8+
export function styleLoader (ext, loaders = []) {
9+
// https://github.com/webpack-contrib/css-loader
10+
const cssLoader = {
11+
loader: 'css-loader',
12+
options: {
13+
minimize: true,
14+
sourceMap: true,
15+
// https://github.com/webpack/loader-utils#root-relative-urls
16+
root: '~',
17+
alias: {
18+
'/static': join(this.options.srcDir, 'static'),
19+
'/assets': join(this.options.srcDir, 'assets')
20+
}
21+
}
22+
}
23+
24+
// https://github.com/vuejs/vue-style-loader
25+
const vueStyleLoader = {
26+
loader: 'vue-style-loader',
27+
options: {
28+
sourceMap: true
29+
}
30+
}
31+
832
if (extractStyles.call(this)) {
933
return ExtractTextPlugin.extract({
10-
use: ['css-loader?minify&sourceMap'].concat(loader),
11-
fallback: 'vue-style-loader?sourceMap'
34+
use: [cssLoader].concat(loaders),
35+
fallback: vueStyleLoader
1236
})
1337
}
14-
return ['vue-style-loader?sourceMap', 'css-loader?sourceMap'].concat(loader)
38+
39+
return [vueStyleLoader, cssLoader].concat(loaders)
1540
}

0 commit comments

Comments
 (0)