-
Notifications
You must be signed in to change notification settings - Fork 88
/
utils.js
81 lines (76 loc) · 2.67 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const path = require('path')
const config = require('../config')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
exports.conditionalCompiler = {
loader: 'js-conditional-compile-loader',
options: {
isDebug: process.env.NODE_ENV === 'development', // optional, this expression is default
envTest: process.env.ENV_CONFIG === 'test', // any prop name you want, used for /* IFTRUE_evnTest ...js code... FITRUE_evnTest */
isPreview: process.env.npm_config_preview, // npm run build-demo --preview, for mock client data
//java环境把.aspx替换为.do。 执行npm run build --java
changeSource: process.env.npm_config_java ? source => source.replace(/\.aspx\b/ig, '.do') : null,
}
}
exports.assetsPath = function (_path) {
const assetsSubDirectory = config.isBuild
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory
return path.posix.join(assetsSubDirectory, _path)
}
exports.styleLoaders = function (options) {
options = options || {}
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: options.sourceMap,
esModule: false
}
}
function getCssRule(extension, loader, loaderOptions) {
const use = [ 'vue-style-loader', cssLoader]
use.push(getPostCssLoader(options.sourceMap));
if (loader) {
use.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, { sourceMap: options.sourceMap })
})
}
if (options.extract) {
use.splice(1, 0, {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../../', // index.html 相对于 h5/css 目录
esModule: false,
}
})
}
use.push(exports.conditionalCompiler)
return {
test: new RegExp('\\.' + extension + '$'),
use: use
}
}
const result = [
getCssRule('css', false),
getCssRule('postcss', false),
getCssRule('less', 'less'),
getCssRule('sass', 'sass', { implementation: require('sass'), indentedSyntax: true }),
getCssRule('scss', 'sass', { implementation: require('sass') }),
getCssRule('stylus', 'stylus'),
getCssRule('styl', 'stylus')
];
return result;
}
function getPostCssLoader(sourceMap) {
return {
loader: 'postcss-loader',
options: {
sourceMap: sourceMap,
postcssOptions: {
plugins: [
require('autoprefixer')({}),
]
}
}
}
}