提交 ade02c8a 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'dev' of https://github.com/dcloudio/uni-app into alpha

const semver = require('semver')
let sassLoaderVersion
try {
sassLoaderVersion = semver.major(require('sass-loader/package.json').version)
} catch (e) {}
const SCSS = const SCSS =
` `
$uni-color-primary: #007aff; $uni-color-primary: #007aff;
...@@ -100,7 +107,9 @@ $uni-font-size-subtitle: 36rpx ...@@ -100,7 +107,9 @@ $uni-font-size-subtitle: 36rpx
$uni-color-paragraph: #3F536E // 文章段落颜色 $uni-color-paragraph: #3F536E // 文章段落颜色
$uni-font-size-paragraph: 30rpx $uni-font-size-paragraph: 30rpx
` `
module.exports = { module.exports = {
SCSS, SCSS,
SASS SASS,
sassLoaderVersion
} }
import { version } from '../package.json'; import { version } from '../package.json';
const STAT_VERSION = version; const STAT_VERSION = version;
const STAT_URL = 'https://uniapp.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://uniapp.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; const PAGE_PVER_TIME = 1800;
const APP_PVER_TIME = 300; const APP_PVER_TIME = 300;
const OPERATING_TIME = 10; const OPERATING_TIME = 10;
......
...@@ -2,8 +2,8 @@ import { ...@@ -2,8 +2,8 @@ import {
version version
} from '../package.json' } from '../package.json'
export const STAT_VERSION = version export const STAT_VERSION = version
export const STAT_URL = 'https://uniapp.dcloud.io/uni/stat' export const STAT_URL = 'https://tongji.dcloud.io/uni/stat'
export const STAT_H5_URL = 'https://uniapp.dcloud.io/uni/stat.gif' export const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'
export const STAT_KEY = 'qkTHEIegZGcL5iy3' export const STAT_KEY = 'qkTHEIegZGcL5iy3'
export const PAGE_PVER_TIME = 1800 export const PAGE_PVER_TIME = 1800
export const APP_PVER_TIME = 300 export const APP_PVER_TIME = 300
......
const fs = require('fs')
const path = require('path')
const { const {
// jsPreprocessOptions, getPlatformScss,
getPlatformSass,
nvueCssPreprocessOptions nvueCssPreprocessOptions
// htmlPreprocessOptions
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const {
sassLoaderVersion
} = require('@dcloudio/uni-cli-shared/lib/scss')
const nvueStyleLoader = { const nvueStyleLoader = {
loader: '@dcloudio/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style' loader: '@dcloudio/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style'
} }
...@@ -25,11 +32,41 @@ const postcssLoader = { ...@@ -25,11 +32,41 @@ const postcssLoader = {
} }
} }
// sass 全局变量
const isSass = fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni.sass'))
const isScss = fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni.scss'))
let sassData = isSass ? getPlatformSass() : getPlatformScss()
if (isSass) {
sassData = `@import "@/uni.sass"`
} else if (isScss) {
sassData = `${sassData}
@import "@/uni.scss";`
}
const scssLoader = {
loader: 'sass-loader',
options: {
sourceMap: false
}
}
const sassLoader = { const sassLoader = {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
sourceMap: false, sourceMap: false
data: '' }
}
if (sassLoaderVersion < 8) {
scssLoader.options.data = sassData
sassLoader.options.data = sassData
sassLoader.options.indentedSyntax = true
} else {
scssLoader.options.prependData = sassData
sassLoader.options.prependData = sassData
sassLoader.options.sassOptions = {
indentedSyntax: true
} }
} }
...@@ -74,7 +111,7 @@ module.exports = [{ ...@@ -74,7 +111,7 @@ module.exports = [{
oneOf: createOneOf() oneOf: createOneOf()
}, { }, {
test: /\.scss$/, test: /\.scss$/,
oneOf: createOneOf(sassLoader) oneOf: createOneOf(scssLoader)
}, { }, {
test: /\.sass$/, test: /\.sass$/,
oneOf: createOneOf(sassLoader) oneOf: createOneOf(sassLoader)
......
function resolve (module) {
try {
return require.resolve(module)
} catch (e) {}
return module
}
exports.cssLoaders = function (options) {
options = options || {}
const cssLoader = {
loader: resolve('css-loader'),
options: {
sourceMap: options.sourceMap
}
}
const postcssLoader = {
loader: resolve('postcss-loader'),
options: {
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
const generateLoaders = (loader, loaderOptions) => {
let loaders = options.useVue ? [cssLoader] : []
if (options.usePostCSS) {
loaders.push(postcssLoader)
}
if (loader) {
loaders.push({
loader: resolve(loader + '-loader'),
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
if (options.useVue) {
return [resolve('vue-style-loader')].concat(loaders)
} else {
return loaders
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
less: generateLoaders('less'),
sass: generateLoaders('sass', {
indentedSyntax: true
}),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function (options) {
const output = []
const loaders = exports.cssLoaders(options)
for (const extension in loaders) {
const loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
use: loader
})
}
return output
}
const path = require('path') const path = require('path')
const {
sassLoaderVersion
} = require('@dcloudio/uni-cli-shared/lib/scss')
function resolve (dir) { function resolve (dir) {
return path.resolve(__dirname, '..', dir) return path.resolve(__dirname, '..', dir)
} }
...@@ -59,6 +63,22 @@ module.exports = function chainWebpack (platformOptions) { ...@@ -59,6 +63,22 @@ module.exports = function chainWebpack (platformOptions) {
}) })
}) })
if (sassLoaderVersion >= 8) { // check indentedSyntax
// vue cli 3 and sass-loader 8
cssTypes.forEach(type => {
webpackConfig.module.rule('sass').oneOf(type).use('sass-loader').tap(options => {
if (options.indentedSyntax) {
if (!options.sassOptions) {
options.sassOptions = {}
}
options.sassOptions.indentedSyntax = true
delete options.indentedSyntax
}
return options
})
})
}
platformOptions.chainWebpack(webpackConfig) platformOptions.chainWebpack(webpackConfig)
// define // define
webpackConfig webpackConfig
......
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const {
sassLoaderVersion
} = require('@dcloudio/uni-cli-shared/lib/scss')
module.exports = function initOptions (options) { module.exports = function initOptions (options) {
const { const {
getPlatformScss, getPlatformScss,
...@@ -55,14 +59,17 @@ module.exports = function initOptions (options) { ...@@ -55,14 +59,17 @@ module.exports = function initOptions (options) {
let sassData = isSass ? getPlatformSass() : getPlatformScss() let sassData = isSass ? getPlatformSass() : getPlatformScss()
if (isSass) { if (isSass) {
sassData = `${sassData} sassData = `@import "@/uni.sass"`
@import "@/uni.sass"`
} else if (isScss) { } else if (isScss) {
sassData = `${sassData} sassData = `${sassData}
@import "@/uni.scss";` @import "@/uni.scss";`
} }
if (sassLoaderVersion < 8) {
options.css.loaderOptions.sass.data = sassData options.css.loaderOptions.sass.data = sassData
} else {
options.css.loaderOptions.sass.prependData = sassData
}
let userPostcssConfigPath = path.resolve(process.env.UNI_INPUT_DIR, 'postcss.config.js') let userPostcssConfigPath = path.resolve(process.env.UNI_INPUT_DIR, 'postcss.config.js')
if (fs.existsSync(userPostcssConfigPath)) { if (fs.existsSync(userPostcssConfigPath)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册