1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const runner_utils_1 = require("@tarojs/runner-utils");
|
13 | exports.default = (ctx, opts) => {
|
14 | ctx.modifyWebpackChain(({ chain }) => __awaiter(void 0, void 0, void 0, function* () {
|
15 | const { enableSourceMap = true } = opts;
|
16 | const taroEnv = process.env.TARO_ENV;
|
17 | if (taroEnv) {
|
18 | const sass = require('node-sass');
|
19 | const currentPlatform = ctx.platforms.get(taroEnv);
|
20 | if (!currentPlatform)
|
21 | return;
|
22 | const { sass: sassOption } = ctx.initialConfig;
|
23 | const platformConfig = ctx.initialConfig[currentPlatform.useConfigName];
|
24 | const defaultSassLoaderOption = {
|
25 | sourceMap: enableSourceMap,
|
26 | implementation: sass,
|
27 | sassOptions: {
|
28 | outputStyle: 'expanded'
|
29 | }
|
30 | };
|
31 | const newSassLoaderOption = yield runner_utils_1.getSassLoaderOption({
|
32 | sass: sassOption,
|
33 | sassLoaderOption: platformConfig === null || platformConfig === void 0 ? void 0 : platformConfig.sassLoaderOption
|
34 | });
|
35 | chain.module
|
36 | .rule('addChainStyleSass')
|
37 | .test(ctx.helper.REG_SASS)
|
38 | .pre()
|
39 | .use('resolveUrl')
|
40 | .loader(require.resolve('resolve-url-loader'))
|
41 | .end()
|
42 | .use('sass')
|
43 | .loader(require.resolve('sass-loader'))
|
44 | .options(Object.assign({}, defaultSassLoaderOption, newSassLoaderOption))
|
45 | .end();
|
46 | }
|
47 | }));
|
48 | };
|