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

fix: preprocess scss

上级 b5a4d9d9
...@@ -56,14 +56,14 @@ if (isSass) { ...@@ -56,14 +56,14 @@ if (isSass) {
} }
const scssLoader = { const scssLoader = {
loader: 'sass-loader', loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
options: { options: {
sourceMap: false sourceMap: false
} }
} }
const sassLoader = { const sassLoader = {
loader: 'sass-loader', loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
options: { options: {
sourceMap: false sourceMap: false
} }
......
...@@ -38,6 +38,11 @@ const matchCss = /\.css$/i; ...@@ -38,6 +38,11 @@ const matchCss = /\.css$/i;
* @param {Function<string>} addNormalizedDependency * @param {Function<string>} addNormalizedDependency
* @returns {Importer} * @returns {Importer}
*/ */
const fs = require('fs')
const preprocessor = require('../../webpack-preprocess-loader/preprocess/lib/preprocess')
const {
cssPreprocessOptions
} = require('@dcloudio/uni-cli-shared')
function webpackImporter(resourcePath, resolve, addNormalizedDependency) { function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
function dirContextFrom(fileContext) { function dirContextFrom(fileContext) {
...@@ -51,6 +56,18 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) { ...@@ -51,6 +56,18 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
// Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come // Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come
// in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass. // in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass.
addNormalizedDependency(resolvedFile); addNormalizedDependency(resolvedFile);
const file = resolvedFile.replace(matchCss, '')
if (fs.existsSync(file)) {
const contents = fs.readFileSync(file, 'utf8')
if (contents.includes('#endif')) {
return {
file,
contents: preprocessor.preprocess(contents, cssPreprocessOptions.context, {
type: cssPreprocessOptions.type
})
}
}
}
return { return {
// By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it. // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
file: resolvedFile.replace(matchCss, '') file: resolvedFile.replace(matchCss, '')
...@@ -72,4 +89,4 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) { ...@@ -72,4 +89,4 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
} }
var _default = webpackImporter; var _default = webpackImporter;
exports.default = _default; exports.default = _default;
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册