Files: 5b2e405d30a0a28a8d6b43dd4ec8b16cdba28cf8 / build / utils.js
1949 bytesRaw
1 | var path = require('path') |
2 | var config = require('../config') |
3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') |
4 | |
5 | exports.assetsPath = function (_path) { |
6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' |
7 | ? config.build.assetsSubDirectory |
8 | : config.dev.assetsSubDirectory |
9 | return path.posix.join(assetsSubDirectory, _path) |
10 | } |
11 | |
12 | exports.cssLoaders = function (options) { |
13 | options = options || {} |
14 | |
15 | var cssLoader = { |
16 | loader: 'css-loader', |
17 | options: { |
18 | minimize: process.env.NODE_ENV === 'production', |
19 | sourceMap: options.sourceMap |
20 | } |
21 | } |
22 | |
23 | // generate loader string to be used with extract text plugin |
24 | function generateLoaders (loader, loaderOptions) { |
25 | var loaders = [cssLoader] |
26 | if (loader) { |
27 | loaders.push({ |
28 | loader: loader + '-loader', |
29 | options: Object.assign({}, loaderOptions, { |
30 | sourceMap: options.sourceMap |
31 | }) |
32 | }) |
33 | } |
34 | |
35 | // Extract CSS when that option is specified |
36 | // (which is the case during production build) |
37 | if (options.extract) { |
38 | return ExtractTextPlugin.extract({ |
39 | use: loaders, |
40 | fallback: 'vue-style-loader' |
41 | }) |
42 | } else { |
43 | return ['vue-style-loader'].concat(loaders) |
44 | } |
45 | } |
46 | |
47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html |
48 | return { |
49 | css: generateLoaders(), |
50 | postcss: generateLoaders(), |
51 | less: generateLoaders('less'), |
52 | sass: generateLoaders('sass', { indentedSyntax: true }), |
53 | scss: generateLoaders('sass'), |
54 | stylus: generateLoaders('stylus'), |
55 | styl: generateLoaders('stylus') |
56 | } |
57 | } |
58 | |
59 | // Generate loaders for standalone style files (outside of .vue) |
60 | exports.styleLoaders = function (options) { |
61 | var output = [] |
62 | var loaders = exports.cssLoaders(options) |
63 | for (var extension in loaders) { |
64 | var loader = loaders[extension] |
65 | output.push({ |
66 | test: new RegExp('\\.' + extension + '$'), |
67 | use: loader |
68 | }) |
69 | } |
70 | return output |
71 | } |
72 |
Built with git-ssb-web