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

fix(nvue): preprocess scss

上级 8f917136
const uniI18n = require('@dcloudio/uni-cli-i18n') const uniI18n = require('@dcloudio/uni-cli-i18n')
function isPlainObject(a) { function isPlainObject (a) {
if (a === null) { if (a === null) {
return false return false
} }
...@@ -8,7 +8,7 @@ function isPlainObject(a) { ...@@ -8,7 +8,7 @@ function isPlainObject(a) {
} }
module.exports = { module.exports = {
initCustomScript(name, pkgPath) { initCustomScript (name, pkgPath) {
const pkg = require(pkgPath) const pkg = require(pkgPath)
const uniAppOptions = pkg['uni-app'] const uniAppOptions = pkg['uni-app']
...@@ -24,7 +24,9 @@ module.exports = { ...@@ -24,7 +24,9 @@ module.exports = {
} }
if (!scriptOptions.env || !scriptOptions.env.UNI_PLATFORM) { if (!scriptOptions.env || !scriptOptions.env.UNI_PLATFORM) {
console.error(uniI18n.__('cliShared.requireConfigUniPlatform', { 0: `package.json->uni-app->scripts->${name}->env ` })) console.error(uniI18n.__('cliShared.requireConfigUniPlatform', {
0: `package.json->uni-app->scripts->${name}->env `
}))
process.exit(0) process.exit(0)
} }
...@@ -32,7 +34,9 @@ module.exports = { ...@@ -32,7 +34,9 @@ module.exports = {
Object.keys(uniAppOptions.scripts).forEach(scriptName => { Object.keys(uniAppOptions.scripts).forEach(scriptName => {
if (scriptName !== name) { if (scriptName !== name) {
const define = uniAppOptions.scripts[scriptName].define const define = uniAppOptions.scripts[scriptName].define
Object.keys(define).forEach(name => define[name] = false) Object.keys(define).forEach(name => {
define[name] = false
})
Object.assign(scriptOptions.define, define) Object.assign(scriptOptions.define, define)
} }
}) })
...@@ -46,4 +50,4 @@ module.exports = { ...@@ -46,4 +50,4 @@ module.exports = {
return scriptOptions return scriptOptions
} }
} }
...@@ -58,6 +58,7 @@ if (isSass) { ...@@ -58,6 +58,7 @@ if (isSass) {
const scssLoader = { const scssLoader = {
loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader', loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
options: { options: {
nvue: true,
sourceMap: false sourceMap: false
} }
} }
...@@ -65,6 +66,7 @@ const scssLoader = { ...@@ -65,6 +66,7 @@ const scssLoader = {
const sassLoader = { const sassLoader = {
loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader', loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
options: { options: {
nvue: true,
sourceMap: false sourceMap: false
} }
} }
......
...@@ -33,6 +33,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de ...@@ -33,6 +33,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
*/ */
function loader(content) { function loader(content) {
const options = (0, _loaderUtils.getOptions)(this) || {}; const options = (0, _loaderUtils.getOptions)(this) || {};
// fixed by xxxxxx
const isNVue = !!options.nvue
delete options.nvue
(0, _schemaUtils.default)(_options.default, options, { (0, _schemaUtils.default)(_options.default, options, {
name: 'Sass Loader', name: 'Sass Loader',
baseDataPath: 'options' baseDataPath: 'options'
...@@ -54,7 +57,7 @@ function loader(content) { ...@@ -54,7 +57,7 @@ function loader(content) {
mainFiles: ['_index', 'index', '...'], mainFiles: ['_index', 'index', '...'],
extensions: ['.scss', '.sass', '.css', '...'] extensions: ['.scss', '.sass', '.css', '...']
}); });
sassOptions.importer.push((0, _webpackImporter.default)(this.resourcePath, resolve, addNormalizedDependency)); sassOptions.importer.push((0, _webpackImporter.default)(this.resourcePath, resolve, addNormalizedDependency, isNVue));
} // Skip empty files, otherwise it will stop webpack, see issue #21 } // Skip empty files, otherwise it will stop webpack, see issue #21
...@@ -111,4 +114,4 @@ function loader(content) { ...@@ -111,4 +114,4 @@ function loader(content) {
} }
var _default = loader; var _default = loader;
exports.default = _default; exports.default = _default;
\ No newline at end of file
...@@ -41,10 +41,11 @@ const matchCss = /\.css$/i; ...@@ -41,10 +41,11 @@ const matchCss = /\.css$/i;
const fs = require('fs') const fs = require('fs')
const preprocessor = require('../../webpack-preprocess-loader/preprocess/lib/preprocess') const preprocessor = require('../../webpack-preprocess-loader/preprocess/lib/preprocess')
const { const {
cssPreprocessOptions cssPreprocessOptions,
nvueCssPreprocessOptions
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
// fixed by xxxxxx
function webpackImporter(resourcePath, resolve, addNormalizedDependency) { function webpackImporter(resourcePath, resolve, addNormalizedDependency, isNVue) {
function dirContextFrom(fileContext) { function dirContextFrom(fileContext) {
return _path.default.dirname( // The first file is 'stdin' when we're using the data option return _path.default.dirname( // The first file is 'stdin' when we're using the data option
fileContext === 'stdin' ? resourcePath : fileContext); fileContext === 'stdin' ? resourcePath : fileContext);
...@@ -63,7 +64,7 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) { ...@@ -63,7 +64,7 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
if (contents.includes('#endif')) { if (contents.includes('#endif')) {
return { return {
file, file,
contents: preprocessor.preprocess(contents, cssPreprocessOptions.context, { contents: preprocessor.preprocess(contents, isNVue ? nvueCssPreprocessOptions.context : cssPreprocessOptions.context, {
type: cssPreprocessOptions.type type: cssPreprocessOptions.type
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册