From 128ef4140558ca52eb4b876ab8b43ec1553bb2ab Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 26 May 2020 15:11:53 +0800 Subject: [PATCH 01/15] =?UTF-8?q?feat(cli):=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=BD=93?= =?UTF-8?q?=E5=89=8D=20cli=20=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/commands/customCommand.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/taro-cli/src/commands/customCommand.ts b/packages/taro-cli/src/commands/customCommand.ts index 58e7f63cf0d1..7369e194b219 100644 --- a/packages/taro-cli/src/commands/customCommand.ts +++ b/packages/taro-cli/src/commands/customCommand.ts @@ -1,5 +1,7 @@ import { Kernel } from '@tarojs/service' +import { getPkgVersion } from '../util' + export default function customCommand ( command: string, kernel: Kernel, @@ -18,7 +20,8 @@ export default function customCommand ( opts: { _: args._, options, - isHelp: args.h + isHelp: args.h, + cliVersion: getPkgVersion() } }) } From c6489044f93a0ac6b6b60cb432ff31cd8eb09f24 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 26 May 2020 21:55:50 +0800 Subject: [PATCH 02/15] =?UTF-8?q?feat(service):=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=BF=A1=E6=81=AF=E4=B8=AD=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83=E4=B8=8A?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E7=9A=84=E7=BC=96=E8=AF=91=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=20platforms=20=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-service/src/Kernel.ts | 1 + packages/taro-service/src/utils/types.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/taro-service/src/Kernel.ts b/packages/taro-service/src/Kernel.ts index 238cda63f1f7..37b210a825eb 100644 --- a/packages/taro-service/src/Kernel.ts +++ b/packages/taro-service/src/Kernel.ts @@ -188,6 +188,7 @@ export default class Kernel extends EventEmitter { const kernelApis = [ 'appPath', 'plugins', + 'platforms', 'paths', 'helper', 'runOpts', diff --git a/packages/taro-service/src/utils/types.ts b/packages/taro-service/src/utils/types.ts index 652f05a2c54e..899ffd858ecd 100644 --- a/packages/taro-service/src/utils/types.ts +++ b/packages/taro-service/src/utils/types.ts @@ -58,5 +58,5 @@ export interface IFileType { export interface IPlatform extends IHook { fileType: IFileType - useConfigName: String + useConfigName: string } From 3fafc5c6af2d2291f2c453d90502463a4b1fecf4 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 26 May 2020 21:56:35 +0800 Subject: [PATCH 03/15] =?UTF-8?q?refactor:=20=E6=8B=86=E8=A7=A3=E5=87=BA?= =?UTF-8?q?=20mini-runner=20=E4=B8=AD=E7=9A=84=20sass=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/src/index.ts | 18 +--- .../src/webpack/build.conf.ts | 2 - .../taro-mini-runner/src/webpack/chain.ts | 18 ---- .../__snapshots__/bundler.test.js.snap | 17 ---- .../__snapshots__/compile.test.js.snap | 90 ------------------- .../__tests__/bundler.test.js | 20 ----- .../__tests__/compile.test.js | 69 -------------- .../__tests__/styles/index.scss | 7 -- .../__tests__/styles/mixins.scss | 5 -- .../__tests__/styles/multiple.scss | 18 ---- .../__tests__/styles/single.scss | 17 ---- .../__tests__/styles/variables.scss | 4 - packages/taro-plugin-sass/bundler.js | 24 ----- packages/taro-plugin-sass/index.js | 66 +------------- packages/taro-plugin-sass/jest.config.js | 4 + packages/taro-plugin-sass/package.json | 32 ++++--- packages/taro-plugin-sass/src/index.ts | 33 +++++++ packages/taro-plugin-sass/tsconfig.json | 29 ++++++ packages/taro-runner-utils/src/scss.ts | 6 +- packages/taro-service/types/index.d.ts | 4 + 20 files changed, 101 insertions(+), 382 deletions(-) delete mode 100644 packages/taro-plugin-sass/__tests__/__snapshots__/bundler.test.js.snap delete mode 100644 packages/taro-plugin-sass/__tests__/__snapshots__/compile.test.js.snap delete mode 100644 packages/taro-plugin-sass/__tests__/bundler.test.js delete mode 100644 packages/taro-plugin-sass/__tests__/compile.test.js delete mode 100644 packages/taro-plugin-sass/__tests__/styles/index.scss delete mode 100644 packages/taro-plugin-sass/__tests__/styles/mixins.scss delete mode 100644 packages/taro-plugin-sass/__tests__/styles/multiple.scss delete mode 100644 packages/taro-plugin-sass/__tests__/styles/single.scss delete mode 100644 packages/taro-plugin-sass/__tests__/styles/variables.scss delete mode 100644 packages/taro-plugin-sass/bundler.js create mode 100644 packages/taro-plugin-sass/jest.config.js create mode 100644 packages/taro-plugin-sass/src/index.ts create mode 100644 packages/taro-plugin-sass/tsconfig.json diff --git a/packages/taro-mini-runner/src/index.ts b/packages/taro-mini-runner/src/index.ts index 1fb52aa98fe8..611c7a8e4b73 100644 --- a/packages/taro-mini-runner/src/index.ts +++ b/packages/taro-mini-runner/src/index.ts @@ -1,8 +1,7 @@ import * as webpack from 'webpack' -import { getSassLoaderOption } from '@tarojs/runner-utils' import { PARSE_AST_TYPE } from '@tarojs/helper' -import { IBuildConfig, IOption } from './utils/types' +import { IBuildConfig } from './utils/types' import { printBuildError, bindProdLogger, bindDevLogger } from './utils/logHelper' import buildConf from './webpack/build.conf' @@ -15,24 +14,15 @@ const customizeChain = async (chain, modifyWebpackChainFunc: Function, customize } } -const makeConfig = async (buildConfig: IBuildConfig) => { - const sassLoaderOption: IOption = await getSassLoaderOption(buildConfig) - return { - ...buildConfig, - sassLoaderOption - } -} - export default async function build (appPath: string, config: IBuildConfig) { const mode = config.mode - const newConfig = await makeConfig(config) - const webpackChain = buildConf(appPath, mode, newConfig) - await customizeChain(webpackChain, newConfig.modifyWebpackChain, newConfig.webpackChain) + const webpackChain = buildConf(appPath, mode, config) + await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) const webpackConfig = webpackChain.toConfig() const onBuildFinish = config.onBuildFinish const compiler = webpack(webpackConfig) return new Promise((resolve, reject) => { - if (newConfig.isWatch) { + if (config.isWatch) { bindDevLogger(compiler) compiler.watch({ aggregateTimeout: 300, diff --git a/packages/taro-mini-runner/src/webpack/build.conf.ts b/packages/taro-mini-runner/src/webpack/build.conf.ts index f3ffc2f941be..9225a6257360 100644 --- a/packages/taro-mini-runner/src/webpack/build.conf.ts +++ b/packages/taro-mini-runner/src/webpack/build.conf.ts @@ -46,7 +46,6 @@ export default (appPath: string, mode, config: Partial): any => { defineConstants = emptyObj, env = emptyObj, cssLoaderOption = emptyObj, - sassLoaderOption = emptyObj, lessLoaderOption = emptyObj, stylusLoaderOption = emptyObj, mediaUrlLoaderOption = emptyObj, @@ -180,7 +179,6 @@ export default (appPath: string, mode, config: Partial): any => { cssLoaderOption, lessLoaderOption, - sassLoaderOption, stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index 3fdccd2256b2..ea5b2f3b8b7a 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -4,14 +4,12 @@ import * as path from 'path' import * as CopyWebpackPlugin from 'copy-webpack-plugin' import CssoWebpackPlugin from 'csso-webpack-plugin' import * as MiniCssExtractPlugin from 'mini-css-extract-plugin' -import * as sass from 'node-sass' import { partial } from 'lodash' import { mapKeys, pipe } from 'lodash/fp' import * as UglifyJsPlugin from 'uglifyjs-webpack-plugin' import * as webpack from 'webpack' import { PostcssOption, ICopyOptions, IPostcssOption } from '@tarojs/taro/types/compile' import { - REG_SASS, REG_LESS, REG_STYLUS, REG_STYLE, @@ -98,7 +96,6 @@ export const processEnvOption = partial(mapKeys as any, (key: string) => `proces export const getCssLoader = pipe(mergeOption, partial(getLoader, 'css-loader')) export const getPostcssLoader = pipe(mergeOption, partial(getLoader, 'postcss-loader')) -export const getSassLoader = pipe(mergeOption, partial(getLoader, 'sass-loader')) export const getLessLoader = pipe(mergeOption, partial(getLoader, 'less-loader')) export const getStylusLoader = pipe(mergeOption, partial(getLoader, 'stylus-loader')) export const getUrlLoader = pipe(mergeOption, partial(getLoader, 'url-loader')) @@ -165,7 +162,6 @@ export const getModule = (appPath: string, { cssLoaderOption, lessLoaderOption, - sassLoaderOption, stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, @@ -255,11 +251,6 @@ export const getModule = (appPath: string, { }) } ]) - const sassLoader = getSassLoader([{ - sourceMap: true, - implementation: sass, - outputStyle: 'expanded' - }, sassLoaderOption]) const lessLoader = getLessLoader([{ sourceMap: enableSourceMap }, lessLoaderOption]) const stylusLoader = getStylusLoader([{ sourceMap: enableSourceMap }, stylusLoaderOption]) @@ -310,11 +301,6 @@ export const getModule = (appPath: string, { } const rule: any = { - sass: { - test: REG_SASS, - enforce: 'pre', - use: [sassLoader] - }, less: { test: REG_LESS, enforce: 'pre', @@ -329,10 +315,6 @@ export const getModule = (appPath: string, { test: REG_STYLE, oneOf: cssLoaders }, - // styleFiles: { - // test: REG_STYLE, - // use: [fileLoader] - // }, postcss: { test: REG_STYLE, use: [postcssLoader] diff --git a/packages/taro-plugin-sass/__tests__/__snapshots__/bundler.test.js.snap b/packages/taro-plugin-sass/__tests__/__snapshots__/bundler.test.js.snap deleted file mode 100644 index 7468e4b01b4e..000000000000 --- a/packages/taro-plugin-sass/__tests__/__snapshots__/bundler.test.js.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`getBundleContent test file name and project directory path 1`] = ` -"$color-ui-info: #78A4FA !default; -$color-ui-positive: #13CE66 !default; -$color-ui-negative: #FF4949 !default; -$color-ui-warning: #FFC82C !default; -" -`; - -exports[`getBundleContent test file path 1`] = ` -"$color-ui-info: #78A4FA !default; -$color-ui-positive: #13CE66 !default; -$color-ui-negative: #FF4949 !default; -$color-ui-warning: #FFC82C !default; -" -`; diff --git a/packages/taro-plugin-sass/__tests__/__snapshots__/compile.test.js.snap b/packages/taro-plugin-sass/__tests__/__snapshots__/compile.test.js.snap deleted file mode 100644 index 1b68d74dae52..000000000000 --- a/packages/taro-plugin-sass/__tests__/__snapshots__/compile.test.js.snap +++ /dev/null @@ -1,90 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`compileSass text compile only content 1`] = ` -".index { - background-color: #ececec; } -" -`; - -exports[`compileSass text compile only sass file path 1`] = ` -"body { - font: 100% Helvetica, sans-serif; - color: #333; } -" -`; - -exports[`compileSass text compile sass file and multiple resource file with directory 1`] = ` -".ui-color--info { - color: #78A4FA; } - -.ui-color--positive { - color: #13CE66; } - -.ui-color--negative { - color: #FF4949; } - -.ui-color--warning { - color: #FFC82C; } - -.box { - -webkit-transform: rotate(30deg); - -ms-transform: rotate(30deg); - transform: rotate(30deg); } -" -`; - -exports[`compileSass text compile sass file and multiple resource path 1`] = ` -".ui-color--info { - color: #78A4FA; } - -.ui-color--positive { - color: #13CE66; } - -.ui-color--negative { - color: #FF4949; } - -.ui-color--warning { - color: #FFC82C; } - -.box { - -webkit-transform: rotate(30deg); - -ms-transform: rotate(30deg); - transform: rotate(30deg); } -" -`; - -exports[`compileSass text compile sass file and single resource file with directory 1`] = ` -".index { - font-size: 20px; } - -.ui-color--info { - color: #78A4FA; } - -.ui-color--positive { - color: #13CE66; } - -.ui-color--negative { - color: #FF4949; } - -.ui-color--warning { - color: #FFC82C; } -" -`; - -exports[`compileSass text compile sass file and single resource path 1`] = ` -".index { - font-size: 20px; } - -.ui-color--info { - color: #78A4FA; } - -.ui-color--positive { - color: #13CE66; } - -.ui-color--negative { - color: #FF4949; } - -.ui-color--warning { - color: #FFC82C; } -" -`; diff --git a/packages/taro-plugin-sass/__tests__/bundler.test.js b/packages/taro-plugin-sass/__tests__/bundler.test.js deleted file mode 100644 index edf49d98096a..000000000000 --- a/packages/taro-plugin-sass/__tests__/bundler.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const path = require('path') -const getBundleContent = require('../bundler') - -const filePath = path.resolve(__dirname, '.', 'styles/variables.scss') -const fileConfig = { - name: 'styles/variables.scss', - path: path.resolve(__dirname, '.') -} - -describe('getBundleContent', () => { - test('test file path', async () => { - const res = await getBundleContent(filePath) - expect(res.bundledContent).toMatchSnapshot() - }) - - test('test file name and project directory path', async () => { - const res = await getBundleContent(fileConfig.name, fileConfig.path) - expect(res.bundledContent).toMatchSnapshot() - }) -}) diff --git a/packages/taro-plugin-sass/__tests__/compile.test.js b/packages/taro-plugin-sass/__tests__/compile.test.js deleted file mode 100644 index fc34a1d013d3..000000000000 --- a/packages/taro-plugin-sass/__tests__/compile.test.js +++ /dev/null @@ -1,69 +0,0 @@ -const path = require('path') -const fs = require('fs') -const compileSass = require('../index') - -const sassContent = ` -.index { - background-color: #ececec; -} -` - -const indexPath = path.resolve(__dirname, '.', 'styles/index.scss') - -const singlePath = path.resolve(__dirname, '.', 'styles/single.scss') -const singlePathContent = fs.readFileSync(singlePath) -const singleConfig = { - resource: path.resolve(__dirname, '.', 'styles/variables.scss') -} -const singleConfigWithDirectory = { - resource: 'styles/variables.scss', - projectDirectory: path.resolve(__dirname, '.') -} - -const multiplePath = path.resolve(__dirname, '.', 'styles/multiple.scss') -const multiplePathContent = fs.readFileSync(multiplePath) -const multipleConfig = { - resource: [ - path.resolve(__dirname, '.', 'styles/variables.scss'), - path.resolve(__dirname, '.', 'styles/mixins.scss') - ] -} -const multipleConfigWithDirectory = { - resource: [ - 'styles/variables.scss', - 'styles/mixins.scss' - ], - projectDirectory: path.resolve(__dirname, '.') -} - -describe('compileSass', () => { - test('text compile only content', async () => { - const res = await compileSass(sassContent, '', {}) - expect(res.css.toString()).toMatchSnapshot() - }) - - test('text compile only sass file path', async () => { - const res = await compileSass('', indexPath, {}) - expect(res.css.toString()).toMatchSnapshot() - }) - - test('text compile sass file and single resource path', async () => { - const res = await compileSass(singlePathContent, singlePath, singleConfig) - expect(res.css.toString()).toMatchSnapshot() - }) - - test('text compile sass file and single resource file with directory', async () => { - const res = await compileSass(singlePathContent, singlePath, singleConfigWithDirectory) - expect(res.css.toString()).toMatchSnapshot() - }) - - test('text compile sass file and multiple resource path', async () => { - const res = await compileSass(multiplePathContent, multiplePath, multipleConfig) - expect(res.css.toString()).toMatchSnapshot() - }) - - test('text compile sass file and multiple resource file with directory', async () => { - const res = await compileSass(multiplePathContent, multiplePath, multipleConfigWithDirectory) - expect(res.css.toString()).toMatchSnapshot() - }) -}) diff --git a/packages/taro-plugin-sass/__tests__/styles/index.scss b/packages/taro-plugin-sass/__tests__/styles/index.scss deleted file mode 100644 index 1a72d52fce4c..000000000000 --- a/packages/taro-plugin-sass/__tests__/styles/index.scss +++ /dev/null @@ -1,7 +0,0 @@ -$font-stack: Helvetica, sans-serif; -$primary-color: #333; - -body { - font: 100% $font-stack; - color: $primary-color; -} diff --git a/packages/taro-plugin-sass/__tests__/styles/mixins.scss b/packages/taro-plugin-sass/__tests__/styles/mixins.scss deleted file mode 100644 index 5ad2ecbedb41..000000000000 --- a/packages/taro-plugin-sass/__tests__/styles/mixins.scss +++ /dev/null @@ -1,5 +0,0 @@ -@mixin transform($property) { - -webkit-transform: $property; - -ms-transform: $property; - transform: $property; -} diff --git a/packages/taro-plugin-sass/__tests__/styles/multiple.scss b/packages/taro-plugin-sass/__tests__/styles/multiple.scss deleted file mode 100644 index f307700158f4..000000000000 --- a/packages/taro-plugin-sass/__tests__/styles/multiple.scss +++ /dev/null @@ -1,18 +0,0 @@ -.ui-color { - &--info { - color: $color-ui-info; - } - &--positive { - color: $color-ui-positive; - } - &--negative { - color: $color-ui-negative; - } - &--warning { - color: $color-ui-warning; - } -} - -.box { - @include transform(rotate(30deg)); -} diff --git a/packages/taro-plugin-sass/__tests__/styles/single.scss b/packages/taro-plugin-sass/__tests__/styles/single.scss deleted file mode 100644 index ea296b44cdd2..000000000000 --- a/packages/taro-plugin-sass/__tests__/styles/single.scss +++ /dev/null @@ -1,17 +0,0 @@ -.index { - font-size: 20px; -} -.ui-color { - &--info { - color: $color-ui-info; - } - &--positive { - color: $color-ui-positive; - } - &--negative { - color: $color-ui-negative; - } - &--warning { - color: $color-ui-warning; - } -} diff --git a/packages/taro-plugin-sass/__tests__/styles/variables.scss b/packages/taro-plugin-sass/__tests__/styles/variables.scss deleted file mode 100644 index add794c10eb0..000000000000 --- a/packages/taro-plugin-sass/__tests__/styles/variables.scss +++ /dev/null @@ -1,4 +0,0 @@ -$color-ui-info: #78A4FA !default; -$color-ui-positive: #13CE66 !default; -$color-ui-negative: #FF4949 !default; -$color-ui-warning: #FFC82C !default; diff --git a/packages/taro-plugin-sass/bundler.js b/packages/taro-plugin-sass/bundler.js deleted file mode 100644 index 1839d5a51686..000000000000 --- a/packages/taro-plugin-sass/bundler.js +++ /dev/null @@ -1,24 +0,0 @@ -const Bundler = require('scss-bundle').Bundler - -/** - * Return bundled sass content. - * - * @param {string} url Absolute file path. - * @param {(string | undefined)} projectDirectory Absolute project location, where node_modules are located. Used for resolving tilde imports. - * @returns Bundle result. - */ -async function getBundleContent(url, projectDirectory = undefined) { - let bundler = undefined - if (projectDirectory) { - bundler = new Bundler(undefined, projectDirectory) - } else { - bundler = new Bundler() - } - if (!bundler) { - throw new ReferenceError(`'bundler' is not defined.`) - } - const res = await bundler.Bundle(url) - return res -} - -module.exports = getBundleContent diff --git a/packages/taro-plugin-sass/index.js b/packages/taro-plugin-sass/index.js index 5fbd009f4acf..437a6d4788f4 100644 --- a/packages/taro-plugin-sass/index.js +++ b/packages/taro-plugin-sass/index.js @@ -1,64 +1,2 @@ -const sass = require('node-sass') -const getBundleContent = require('./bundler') - -module.exports = function compileSass (content, file, config) { - return new Promise(async (resolve, reject) => { - let bundledContent = '' - - // when plugins.sass only configured resource property - if (config.resource && !config.projectDirectory) { - const { resource } = config - try { - if (typeof resource === 'string') { - const res = await getBundleContent(resource) - bundledContent += res.bundledContent - } - if (Array.isArray(resource)) { - for (const url of resource) { - const res = await getBundleContent(url) - bundledContent += res.bundledContent - } - } - } catch (e) { - reject(e) - } - } - - // check resource & projectDirectory property - // projectDirectory used for resolving tilde imports - if (config.resource && config.projectDirectory) { - const { resource, projectDirectory } = config - try { - if (typeof resource === 'string') { - const res = await getBundleContent(resource, projectDirectory) - bundledContent += res.bundledContent - } - if (Array.isArray(resource)) { - for (const url of resource) { - const res = await getBundleContent(url, projectDirectory) - bundledContent += res.bundledContent - } - } - } catch (e) { - reject(e) - } - } - - if (config.data) { - bundledContent += config.data - } - - const opts = Object.assign({}, config, { - file, - data: bundledContent ? bundledContent + (content ? content : '') : content - }) - - let result - try { - result = sass.renderSync(opts) - } catch (e) { - reject(e) - } - resolve(result) - }) -} +module.exports = require('./dist/index.js').default +module.exports.default = module.exports diff --git a/packages/taro-plugin-sass/jest.config.js b/packages/taro-plugin-sass/jest.config.js new file mode 100644 index 000000000000..758fa1330e87 --- /dev/null +++ b/packages/taro-plugin-sass/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +} diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index cb24bbcc627a..ee1068c487ee 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,15 +1,22 @@ { "name": "@tarojs/plugin-sass", "version": "2.2.7", - "description": "Taro编译sass文件", + "description": "Taro webpack sass config plugin", "main": "index.js", - "files": [ - "bundler.js", - "index.js" - ], "scripts": { - "test": "jest" + "build": "npm run clean && npm run prod", + "dev": "tsc -w", + "prod": "tsc", + "clean": "rimraf dist", + "test": "jest", + "test:dev": "jest --watch" }, + "files": [ + "src", + "dist", + "index.js", + "package.json" + ], "repository": { "type": "git", "url": "git+https://github.com/NervJS/taro.git" @@ -20,11 +27,16 @@ "author": "luckyadam", "license": "MIT", "dependencies": { - "node-sass": "^4.12.0", - "scss-bundle": "^2.5.1" + "@tarojs/runner-utils": "2.2.7", + "@tarojs/service": "2.2.7", + "node-sass": "4.14.1", + "sass-loader": "8.0.2" }, "devDependencies": { - "@types/jest": "^24.0.19", - "jest": "^24.9.0" + "@types/node": "^14.0.5", + "jest": "^26.0.1", + "rimraf": "^3.0.2", + "ts-jest": "^26.0.0", + "typescript": "^3.9.3" } } diff --git a/packages/taro-plugin-sass/src/index.ts b/packages/taro-plugin-sass/src/index.ts new file mode 100644 index 000000000000..559f3019e970 --- /dev/null +++ b/packages/taro-plugin-sass/src/index.ts @@ -0,0 +1,33 @@ +import { IPluginContext } from '@tarojs/service' +import { getSassLoaderOption } from '@tarojs/runner-utils' + +export default (ctx: IPluginContext) => { + ctx.modifyWebpackChain(async ({ chain }) => { + const sass = require('node-sass') + const defaultSassLoaderOption = { + sourceMap: true, + implementation: sass, + sassOptions: { + outputStyle: 'expanded' + } + } + const taroEnv = process.env.TARO_ENV + if (taroEnv) { + const currentPlatform = ctx.platforms.get(taroEnv) + if (!currentPlatform) return + const { sass: sassOption } = ctx.initialConfig + const platformConfig = ctx.initialConfig[currentPlatform.useConfigName] + const newSassLoaderOption = await getSassLoaderOption({ + sass: sassOption, + sassLoaderOption: platformConfig!.sassLoaderOption + }) + chain.module + .rule('style') + .test(/\.s[ac]ss$/i) + .pre() + .use('sass') + .loader(require.resolve('sass-loader')) + .options(Object.assign({}, defaultSassLoaderOption, newSassLoaderOption)) + } + }) +} diff --git a/packages/taro-plugin-sass/tsconfig.json b/packages/taro-plugin-sass/tsconfig.json new file mode 100644 index 000000000000..522fe3c86d15 --- /dev/null +++ b/packages/taro-plugin-sass/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowJs": true, + "baseUrl": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "dist/", + "preserveConstEnums": true, + "removeComments": false, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": false, + "strictNullChecks": true, + "target": "es2015", + "traceResolution": false, + "types": ["jest"] + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/__tests__" + ] +} diff --git a/packages/taro-runner-utils/src/scss.ts b/packages/taro-runner-utils/src/scss.ts index b546c09afea3..3ad51ed1c191 100644 --- a/packages/taro-runner-utils/src/scss.ts +++ b/packages/taro-runner-utils/src/scss.ts @@ -16,13 +16,13 @@ interface BuildConfig { /** * Return bundled sass content. - * + * * @param {string} url Absolute file path. * @param {(string | undefined)} projectDirectory Absolute project location, where node_modules are located. * Used for resolving tilde imports. * @returns Bundle result. */ -export async function getBundleResult(url: string, +export async function getBundleResult(url: string, projectDirectory: string | undefined = undefined ): Promise { let bundler: Bundler = new Bundler() @@ -91,7 +91,7 @@ export async function getSassLoaderOption( } return { ...sassLoaderOption, - data: sassLoaderOption.data ? `${sassLoaderOption.data}${bundledContent}` : bundledContent + prependData: sassLoaderOption.prependData ? `${sassLoaderOption.prependData}${bundledContent}` : bundledContent } } diff --git a/packages/taro-service/types/index.d.ts b/packages/taro-service/types/index.d.ts index 37def6ebdc60..06f8d5a86b16 100644 --- a/packages/taro-service/types/index.d.ts +++ b/packages/taro-service/types/index.d.ts @@ -19,6 +19,10 @@ export declare interface IPluginContext { * 获取当前执行命令所带的参数 */ runOpts: Object + /** + * 当前运行环境下加载的所有平台及相关配置 + */ + platforms: Map /** * 为包 @tarojs/helper 的快捷使用方式,包含其所有 API */ From aa09a4729f1caace6fde765a1ccb7457b0024895 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 28 May 2020 16:45:21 +0800 Subject: [PATCH 04/15] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20sass=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8F=92=E4=BB=B6=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/src/index.ts | 7 +++-- .../src/webpack/build.conf.ts | 11 +++----- .../taro-mini-runner/src/webpack/chain.ts | 28 +++++++++---------- packages/taro-plugin-sass/src/index.ts | 25 +++++++++-------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/taro-mini-runner/src/index.ts b/packages/taro-mini-runner/src/index.ts index 611c7a8e4b73..bf5cb55318c1 100644 --- a/packages/taro-mini-runner/src/index.ts +++ b/packages/taro-mini-runner/src/index.ts @@ -3,6 +3,7 @@ import { PARSE_AST_TYPE } from '@tarojs/helper' import { IBuildConfig } from './utils/types' import { printBuildError, bindProdLogger, bindDevLogger } from './utils/logHelper' +import baseConf from './webpack/base.conf' import buildConf from './webpack/build.conf' const customizeChain = async (chain, modifyWebpackChainFunc: Function, customizeFunc?: Function) => { @@ -16,8 +17,10 @@ const customizeChain = async (chain, modifyWebpackChainFunc: Function, customize export default async function build (appPath: string, config: IBuildConfig) { const mode = config.mode - const webpackChain = buildConf(appPath, mode, config) - await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + const baseWebpackChain = baseConf(appPath) + await customizeChain(baseWebpackChain, config.modifyWebpackChain, config.webpackChain) + const buildWebpackConf = buildConf(appPath, mode, config, baseWebpackChain) + const webpackChain = baseWebpackChain.merge(buildWebpackConf) const webpackConfig = webpackChain.toConfig() const onBuildFinish = config.onBuildFinish const compiler = webpack(webpackConfig) diff --git a/packages/taro-mini-runner/src/webpack/build.conf.ts b/packages/taro-mini-runner/src/webpack/build.conf.ts index 9225a6257360..bb2beb8a98fb 100644 --- a/packages/taro-mini-runner/src/webpack/build.conf.ts +++ b/packages/taro-mini-runner/src/webpack/build.conf.ts @@ -17,13 +17,11 @@ import { getMiniCssExtractPlugin, getEntry, } from './chain' -import getBaseConf from './base.conf' import { createTarget } from '../plugins/MiniPlugin' const emptyObj = {} -export default (appPath: string, mode, config: Partial): any => { - const chain = getBaseConf(appPath) +export default (appPath: string, mode, config: Partial, chain: any): any => { const { buildAdapter, fileType = { @@ -153,7 +151,7 @@ export default (appPath: string, mode, config: Partial): any => { } } const taroBaseReg = new RegExp(`@tarojs[\\/]taro|@tarojs[\\/]${buildAdapter}`) - chain.merge({ + return { mode, devtool: getDevtool(enableSourceMap), watch: mode === 'development', @@ -189,7 +187,7 @@ export default (appPath: string, mode, config: Partial): any => { babel, alias, nodeModulesPath - }), + }, chain), plugin, optimization: { minimizer, @@ -224,6 +222,5 @@ export default (appPath: string, mode, config: Partial): any => { } } } - }) - return chain + } } diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index ea5b2f3b8b7a..abdc983e11e5 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -171,7 +171,8 @@ export const getModule = (appPath: string, { babel, alias, nodeModulesPath -}) => { +}, chain) => { + const postcssOption: IPostcssOption = postcss || {} const cssModuleOptions: PostcssOption.cssModules = recursiveMerge({}, defaultCssModuleOption, postcssOption.cssModules) @@ -300,27 +301,26 @@ export const getModule = (appPath: string, { }) } + const styleExtRegs = [/\.css$/] + const rules = chain.module.rules.entries() + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) + const rule: any = { - less: { - test: REG_LESS, - enforce: 'pre', - use: [lessLoader] - }, - stylus: { - test: REG_STYLUS, - enforce: 'pre', - use: [stylusLoader] - }, css: { - test: REG_STYLE, + test: styleReg, oneOf: cssLoaders }, postcss: { - test: REG_STYLE, + test: styleReg, use: [postcssLoader] }, customStyle: { - test: REG_STYLE, + test: styleReg, enforce: 'post', use: [extractCssLoader] }, diff --git a/packages/taro-plugin-sass/src/index.ts b/packages/taro-plugin-sass/src/index.ts index 559f3019e970..c9219b7393f3 100644 --- a/packages/taro-plugin-sass/src/index.ts +++ b/packages/taro-plugin-sass/src/index.ts @@ -1,33 +1,36 @@ import { IPluginContext } from '@tarojs/service' import { getSassLoaderOption } from '@tarojs/runner-utils' -export default (ctx: IPluginContext) => { +export default (ctx: IPluginContext, opts) => { ctx.modifyWebpackChain(async ({ chain }) => { - const sass = require('node-sass') - const defaultSassLoaderOption = { - sourceMap: true, - implementation: sass, - sassOptions: { - outputStyle: 'expanded' - } - } + const { enableSourceMap = true } = opts const taroEnv = process.env.TARO_ENV if (taroEnv) { + const sass = require('node-sass') const currentPlatform = ctx.platforms.get(taroEnv) if (!currentPlatform) return const { sass: sassOption } = ctx.initialConfig const platformConfig = ctx.initialConfig[currentPlatform.useConfigName] + + const defaultSassLoaderOption = { + sourceMap: enableSourceMap, + implementation: sass, + sassOptions: { + outputStyle: 'expanded' + } + } const newSassLoaderOption = await getSassLoaderOption({ sass: sassOption, sassLoaderOption: platformConfig!.sassLoaderOption }) chain.module - .rule('style') - .test(/\.s[ac]ss$/i) + .rule('addChainStyleSass') + .test(ctx.helper.REG_SASS) .pre() .use('sass') .loader(require.resolve('sass-loader')) .options(Object.assign({}, defaultSassLoaderOption, newSassLoaderOption)) + .end() } }) } From 7f12edd134ea448b01aa07c24e8a1cf7e99136af Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 28 May 2020 19:48:37 +0800 Subject: [PATCH 05/15] =?UTF-8?q?refactor:=20=E5=AE=8C=E6=88=90=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=AF=B9=20css=20modules=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-mini-runner/src/webpack/chain.ts | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index abdc983e11e5..2f8d93973065 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -10,8 +10,6 @@ import * as UglifyJsPlugin from 'uglifyjs-webpack-plugin' import * as webpack from 'webpack' import { PostcssOption, ICopyOptions, IPostcssOption } from '@tarojs/taro/types/compile' import { - REG_LESS, - REG_STYLUS, REG_STYLE, REG_MEDIA, REG_FONT, @@ -89,15 +87,10 @@ export const mergeOption = ([...options]: IOption[]): IOption => { return recursiveMerge({}, ...options) } -const styleModuleReg = /(.*\.module).*\.(css|s[ac]ss|less|styl)\b/ -const styleGlobalReg = /(.*\.global).*\.(css|s[ac]ss|less|styl)\b/ - export const processEnvOption = partial(mapKeys as any, (key: string) => `process.env.${key}`) as any export const getCssLoader = pipe(mergeOption, partial(getLoader, 'css-loader')) export const getPostcssLoader = pipe(mergeOption, partial(getLoader, 'postcss-loader')) -export const getLessLoader = pipe(mergeOption, partial(getLoader, 'less-loader')) -export const getStylusLoader = pipe(mergeOption, partial(getLoader, 'stylus-loader')) export const getUrlLoader = pipe(mergeOption, partial(getLoader, 'url-loader')) export const getFileLoader = pipe(mergeOption, partial(getLoader, 'file-loader')) export const getWxTransformerLoader = pipe(mergeOption, partial(getLoader, path.resolve(__dirname, '../loaders/wxTransformerLoader'))) @@ -161,8 +154,6 @@ export const getModule = (appPath: string, { enableSourceMap, cssLoaderOption, - lessLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -219,6 +210,18 @@ export const getModule = (appPath: string, { const compileExclude = compile.exclude || [] const compileInclude = compile.include || [] + const styleExtRegs = [/\.css$/] + const rules = chain.module.rules.entries() + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) + + const styleModuleReg = new RegExp(`(.*\.module).*${styleReg.source}`) + const styleGlobalReg = new RegExp(`(.*\.global).*${styleReg.source}`) + if (cssModuleOptions.enable) { const cssLoaderWithModule = getCssLoader(cssOptionsWithModule) let cssModuleCondition @@ -252,9 +255,6 @@ export const getModule = (appPath: string, { }) } ]) - const lessLoader = getLessLoader([{ sourceMap: enableSourceMap }, lessLoaderOption]) - - const stylusLoader = getStylusLoader([{ sourceMap: enableSourceMap }, stylusLoaderOption]) const parsedConstantsReplaceList = {} Object.keys(constantsReplaceList).forEach(key => { @@ -301,15 +301,6 @@ export const getModule = (appPath: string, { }) } - const styleExtRegs = [/\.css$/] - const rules = chain.module.rules.entries() - Object.keys(rules).forEach(item => { - if (/^addChainStyle/.test(item) && rules[item].get('test')) { - styleExtRegs.push(rules[item].get('test')) - } - }) - const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) - const rule: any = { css: { test: styleReg, From 27cfff488ea62d4473256b0942e8bc02d3220adb Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 28 May 2020 19:49:08 +0800 Subject: [PATCH 06/15] =?UTF-8?q?refactor:=20=E5=AE=8C=E6=88=90=20less/sty?= =?UTF-8?q?lus=20=E9=85=8D=E7=BD=AE=E6=8F=92=E4=BB=B6=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/package.json | 8 - .../src/webpack/build.conf.ts | 4 - packages/taro-plugin-less/index.js | 22 +- packages/taro-plugin-less/jest.config.js | 4 + packages/taro-plugin-less/package.json | 27 +- packages/taro-plugin-less/src/index.ts | 28 ++ packages/taro-plugin-less/tsconfig.json | 29 ++ packages/taro-plugin-less/yarn.lock | 403 ------------------ packages/taro-plugin-stylus/index.js | 35 +- packages/taro-plugin-stylus/jest.config.js | 4 + packages/taro-plugin-stylus/package.json | 27 +- packages/taro-plugin-stylus/src/index.ts | 26 ++ .../tests/fixtures/base/style.styl | 1 - .../tests/fixtures/test.styl | 5 - .../taro-plugin-stylus/tests/index.test.js | 12 - packages/taro-plugin-stylus/tsconfig.json | 29 ++ packages/taro-plugin-stylus/yarn.lock | 113 ----- 17 files changed, 172 insertions(+), 605 deletions(-) create mode 100644 packages/taro-plugin-less/jest.config.js create mode 100644 packages/taro-plugin-less/src/index.ts create mode 100644 packages/taro-plugin-less/tsconfig.json delete mode 100644 packages/taro-plugin-less/yarn.lock create mode 100644 packages/taro-plugin-stylus/jest.config.js create mode 100644 packages/taro-plugin-stylus/src/index.ts delete mode 100644 packages/taro-plugin-stylus/tests/fixtures/base/style.styl delete mode 100644 packages/taro-plugin-stylus/tests/fixtures/test.styl delete mode 100644 packages/taro-plugin-stylus/tests/index.test.js create mode 100644 packages/taro-plugin-stylus/tsconfig.json delete mode 100644 packages/taro-plugin-stylus/yarn.lock diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json index 0b63cfb8d681..da7426278d83 100644 --- a/packages/taro-mini-runner/package.json +++ b/packages/taro-mini-runner/package.json @@ -52,12 +52,9 @@ "csso-webpack-plugin": "^2.0.0-beta.1", "file-loader": "^4.0.0", "fs-extra": "^8.0.1", - "less": "^3.10.3", - "less-loader": "^5.0.0", "loader-utils": "^1.2.3", "lodash": "^4.17.11", "mini-css-extract-plugin": "^0.7.0", - "node-sass": "^4.12.0", "ora": "^3.4.0", "postcss-import": "12.0.1", "postcss-loader": "^3.0.0", @@ -65,12 +62,7 @@ "postcss-url": "^8.0.0", "request": "^2.88.0", "resolve": "^2.0.0-next.0", - "sass-loader": "^7.1.0", "sax": "^1.2.4", - "scss-bundle": "^2.5.1", - "stylus": "0.54.7", - "stylus-loader": "^3.0.2", - "tapable": "1.1.3", "uglifyjs-webpack-plugin": "^2.2.0", "url-loader": "^2.0.0", "webpack": "4.41.6", diff --git a/packages/taro-mini-runner/src/webpack/build.conf.ts b/packages/taro-mini-runner/src/webpack/build.conf.ts index bb2beb8a98fb..2258846edec7 100644 --- a/packages/taro-mini-runner/src/webpack/build.conf.ts +++ b/packages/taro-mini-runner/src/webpack/build.conf.ts @@ -44,8 +44,6 @@ export default (appPath: string, mode, config: Partial, chain: any defineConstants = emptyObj, env = emptyObj, cssLoaderOption = emptyObj, - lessLoaderOption = emptyObj, - stylusLoaderOption = emptyObj, mediaUrlLoaderOption = emptyObj, fontUrlLoaderOption = emptyObj, imageUrlLoaderOption = emptyObj, @@ -176,8 +174,6 @@ export default (appPath: string, mode, config: Partial, chain: any enableSourceMap, cssLoaderOption, - lessLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, diff --git a/packages/taro-plugin-less/index.js b/packages/taro-plugin-less/index.js index 8c47fc632415..437a6d4788f4 100644 --- a/packages/taro-plugin-less/index.js +++ b/packages/taro-plugin-less/index.js @@ -1,20 +1,2 @@ -const fs = require('fs') -const less = require('less') - -module.exports = function compileLess (content, file, config) { - return new Promise((resolve, reject) => { - if (!content && !fs.existsSync(file)) { - return resolve({ - css: '' - }) - } - if (!content) { - content = fs.readFileSync(file).toString() - } - config = config || {} - config.filename = file - less.render(content, config).then(res => { - resolve({ css: res.css, imports: res.imports }) - }).catch(reject) - }) -} +module.exports = require('./dist/index.js').default +module.exports.default = module.exports diff --git a/packages/taro-plugin-less/jest.config.js b/packages/taro-plugin-less/jest.config.js new file mode 100644 index 000000000000..758fa1330e87 --- /dev/null +++ b/packages/taro-plugin-less/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +} diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 9c28b5ea0c57..62fad636deda 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,11 +1,22 @@ { "name": "@tarojs/plugin-less", "version": "2.2.7", - "description": "Taro 编译 less 文件", + "description": "Taro webpack less config plugin", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "npm run clean && npm run prod", + "dev": "tsc -w", + "prod": "tsc", + "clean": "rimraf dist", + "test": "jest", + "test:dev": "jest --watch" }, + "files": [ + "src", + "dist", + "index.js", + "package.json" + ], "repository": { "type": "git", "url": "git+https://github.com/NervJS/taro.git" @@ -16,6 +27,16 @@ "author": "luckyadam", "license": "MIT", "dependencies": { - "less": "^3.0.4" + "@tarojs/runner-utils": "2.2.7", + "@tarojs/service": "2.2.7", + "less": "3.11.1", + "less-loader": "6.1.0" + }, + "devDependencies": { + "@types/node": "^14.0.5", + "jest": "^26.0.1", + "rimraf": "^3.0.2", + "ts-jest": "^26.0.0", + "typescript": "^3.9.3" } } diff --git a/packages/taro-plugin-less/src/index.ts b/packages/taro-plugin-less/src/index.ts new file mode 100644 index 000000000000..50c164471839 --- /dev/null +++ b/packages/taro-plugin-less/src/index.ts @@ -0,0 +1,28 @@ +import { IPluginContext } from '@tarojs/service' + +export default (ctx: IPluginContext, opts) => { + ctx.modifyWebpackChain(async ({ chain }) => { + const { enableSourceMap = true } = opts + const taroEnv = process.env.TARO_ENV + if (taroEnv) { + const currentPlatform = ctx.platforms.get(taroEnv) + if (!currentPlatform) return + const less = require('less') + const platformConfig = ctx.initialConfig[currentPlatform.useConfigName] + const lessLoaderOption = platformConfig.lessLoaderOption + const defaultLessLoaderOption = { + sourceMap: enableSourceMap, + implementation: less + } + + chain.module + .rule('addChainStyleLess') + .test(ctx.helper.REG_LESS) + .pre() + .use('less') + .loader(require.resolve('less-loader')) + .options(Object.assign({}, defaultLessLoaderOption, lessLoaderOption)) + .end() + } + }) +} diff --git a/packages/taro-plugin-less/tsconfig.json b/packages/taro-plugin-less/tsconfig.json new file mode 100644 index 000000000000..522fe3c86d15 --- /dev/null +++ b/packages/taro-plugin-less/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowJs": true, + "baseUrl": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "dist/", + "preserveConstEnums": true, + "removeComments": false, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": false, + "strictNullChecks": true, + "target": "es2015", + "traceResolution": false, + "types": ["jest"] + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/__tests__" + ] +} diff --git a/packages/taro-plugin-less/yarn.lock b/packages/taro-plugin-less/yarn.lock deleted file mode 100644 index 75eac509a33a..000000000000 --- a/packages/taro-plugin-less/yarn.lock +++ /dev/null @@ -1,403 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -ajv@^6.5.5: - version "6.10.2" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.2.tgz#d3cea04d6b017b2894ad69040fec8b623eb4bd52" - integrity sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw== - dependencies: - fast-deep-equal "^2.0.1" - fast-json-stable-stringify "^2.0.0" - json-schema-traverse "^0.4.1" - uri-js "^4.2.2" - -asap@~2.0.3: - version "2.0.6" - resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" - integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY= - -asn1@~0.2.3: - version "0.2.4" - resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136" - integrity sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg== - dependencies: - safer-buffer "~2.1.0" - -assert-plus@1.0.0, assert-plus@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" - integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= - -asynckit@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" - integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= - -aws-sign2@~0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" - integrity sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg= - -aws4@^1.8.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" - integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== - -bcrypt-pbkdf@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e" - integrity sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4= - dependencies: - tweetnacl "^0.14.3" - -caseless@~0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" - integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= - -clone@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" - integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18= - -combined-stream@^1.0.6, combined-stream@~1.0.6: - version "1.0.8" - resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" - integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== - dependencies: - delayed-stream "~1.0.0" - -core-util-is@1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" - integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= - -dashdash@^1.12.0: - version "1.14.1" - resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" - integrity sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA= - dependencies: - assert-plus "^1.0.0" - -delayed-stream@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" - integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= - -ecc-jsbn@~0.1.1: - version "0.1.2" - resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9" - integrity sha1-OoOpBOVDUyh4dMVkt1SThoSamMk= - dependencies: - jsbn "~0.1.0" - safer-buffer "^2.1.0" - -errno@^0.1.1: - version "0.1.7" - resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618" - integrity sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg== - dependencies: - prr "~1.0.1" - -extend@~3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" - integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== - -extsprintf@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" - integrity sha1-lpGEQOMEGnpBT4xS48V06zw+HgU= - -extsprintf@^1.2.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" - integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8= - -fast-deep-equal@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" - integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= - -fast-json-stable-stringify@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" - integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I= - -forever-agent@~0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" - integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= - -form-data@~2.3.2: - version "2.3.3" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6" - integrity sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ== - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.6" - mime-types "^2.1.12" - -getpass@^0.1.1: - version "0.1.7" - resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" - integrity sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo= - dependencies: - assert-plus "^1.0.0" - -graceful-fs@^4.1.2: - version "4.2.3" - resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423" - integrity sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ== - -har-schema@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" - integrity sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= - -har-validator@~5.1.0: - version "5.1.3" - resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.1.3.tgz#1ef89ebd3e4996557675eed9893110dc350fa080" - integrity sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== - dependencies: - ajv "^6.5.5" - har-schema "^2.0.0" - -http-signature@~1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1" - integrity sha1-muzZJRFHcvPZW2WmCruPfBj7rOE= - dependencies: - assert-plus "^1.0.0" - jsprim "^1.2.2" - sshpk "^1.7.0" - -image-size@~0.5.0: - version "0.5.5" - resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c" - integrity sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w= - -is-typedarray@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" - integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= - -isstream@~0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" - integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo= - -jsbn@~0.1.0: - version "0.1.1" - resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" - integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM= - -json-schema-traverse@^0.4.1: - version "0.4.1" - resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" - integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== - -json-schema@0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" - integrity sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM= - -json-stringify-safe@~5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" - integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= - -jsprim@^1.2.2: - version "1.4.1" - resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" - integrity sha1-MT5mvB5cwG5Di8G3SZwuXFastqI= - dependencies: - assert-plus "1.0.0" - extsprintf "1.3.0" - json-schema "0.2.3" - verror "1.10.0" - -less@^3.10.3: - version "3.10.3" - resolved "https://registry.yarnpkg.com/less/-/less-3.10.3.tgz#417a0975d5eeecc52cff4bcfa3c09d35781e6792" - integrity sha512-vz32vqfgmoxF1h3K4J+yKCtajH0PWmjkIFgbs5d78E/c/e+UQTnI+lWK+1eQRE95PXM2mC3rJlLSSP9VQHnaow== - dependencies: - clone "^2.1.2" - optionalDependencies: - errno "^0.1.1" - graceful-fs "^4.1.2" - image-size "~0.5.0" - mime "^1.4.1" - mkdirp "^0.5.0" - promise "^7.1.1" - request "^2.83.0" - source-map "~0.6.0" - -mime-db@1.42.0: - version "1.42.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.42.0.tgz#3e252907b4c7adb906597b4b65636272cf9e7bac" - integrity sha512-UbfJCR4UAVRNgMpfImz05smAXK7+c+ZntjaA26ANtkXLlOe947Aag5zdIcKQULAiF9Cq4WxBi9jUs5zkA84bYQ== - -mime-types@^2.1.12, mime-types@~2.1.19: - version "2.1.25" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.25.tgz#39772d46621f93e2a80a856c53b86a62156a6437" - integrity sha512-5KhStqB5xpTAeGqKBAMgwaYMnQik7teQN4IAzC7npDv6kzeU6prfkR67bc87J1kWMPGkoaZSq1npmexMgkmEVg== - dependencies: - mime-db "1.42.0" - -mime@^1.4.1: - version "1.6.0" - resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" - integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== - -minimist@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" - integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= - -mkdirp@^0.5.0: - version "0.5.1" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" - integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= - dependencies: - minimist "0.0.8" - -oauth-sign@~0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455" - integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ== - -performance-now@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" - integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= - -promise@^7.1.1: - version "7.3.1" - resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" - integrity sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg== - dependencies: - asap "~2.0.3" - -prr@~1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" - integrity sha1-0/wRS6BplaRexok/SEzrHXj19HY= - -psl@^1.1.24: - version "1.4.0" - resolved "https://registry.yarnpkg.com/psl/-/psl-1.4.0.tgz#5dd26156cdb69fa1fdb8ab1991667d3f80ced7c2" - integrity sha512-HZzqCGPecFLyoRj5HLfuDSKYTJkAfB5thKBIkRHtGjWwY7p1dAyveIbXIq4tO0KYfDF2tHqPUgY9SDnGm00uFw== - -punycode@^1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" - integrity sha1-wNWmOycYgArY4esPpSachN1BhF4= - -punycode@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" - integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== - -qs@~6.5.2: - version "6.5.2" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" - integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== - -request@^2.83.0: - version "2.88.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" - integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg== - dependencies: - aws-sign2 "~0.7.0" - aws4 "^1.8.0" - caseless "~0.12.0" - combined-stream "~1.0.6" - extend "~3.0.2" - forever-agent "~0.6.1" - form-data "~2.3.2" - har-validator "~5.1.0" - http-signature "~1.2.0" - is-typedarray "~1.0.0" - isstream "~0.1.2" - json-stringify-safe "~5.0.1" - mime-types "~2.1.19" - oauth-sign "~0.9.0" - performance-now "^2.1.0" - qs "~6.5.2" - safe-buffer "^5.1.2" - tough-cookie "~2.4.3" - tunnel-agent "^0.6.0" - uuid "^3.3.2" - -safe-buffer@^5.0.1, safe-buffer@^5.1.2: - version "5.2.0" - resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519" - integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== - -safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0: - version "2.1.2" - resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" - integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== - -source-map@~0.6.0: - version "0.6.1" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" - integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== - -sshpk@^1.7.0: - version "1.16.1" - resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" - integrity sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg== - dependencies: - asn1 "~0.2.3" - assert-plus "^1.0.0" - bcrypt-pbkdf "^1.0.0" - dashdash "^1.12.0" - ecc-jsbn "~0.1.1" - getpass "^0.1.1" - jsbn "~0.1.0" - safer-buffer "^2.0.2" - tweetnacl "~0.14.0" - -tough-cookie@~2.4.3: - version "2.4.3" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781" - integrity sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ== - dependencies: - psl "^1.1.24" - punycode "^1.4.1" - -tunnel-agent@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" - integrity sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0= - dependencies: - safe-buffer "^5.0.1" - -tweetnacl@^0.14.3, tweetnacl@~0.14.0: - version "0.14.5" - resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" - integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= - -uri-js@^4.2.2: - version "4.2.2" - resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" - integrity sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== - dependencies: - punycode "^2.1.0" - -uuid@^3.3.2: - version "3.3.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866" - integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ== - -verror@1.10.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400" - integrity sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA= - dependencies: - assert-plus "^1.0.0" - core-util-is "1.0.2" - extsprintf "^1.2.0" diff --git a/packages/taro-plugin-stylus/index.js b/packages/taro-plugin-stylus/index.js index 0b3f35dd75a2..437a6d4788f4 100644 --- a/packages/taro-plugin-stylus/index.js +++ b/packages/taro-plugin-stylus/index.js @@ -1,33 +1,2 @@ -const fs = require('fs') -const path = require('path') -const stylus = require('stylus') - -module.exports = function compileStylus (content, file, config) { - return new Promise((resolve, reject) => { - if (!content && !fs.existsSync(file)) { - return resolve({ - css: '' - }) - } - if (!content) { - content = fs.readFileSync(file).toString() - } - const opath = path.parse(file) - config.paths = [opath.dir].concat(config.paths || []) - config.filename = opath.base - const instance = stylus(content, { filename: file }) - for (const k in config) { - instance.set(k, config[k]) - } - let imports = instance.deps() - instance.render((err, css) => { - if (err) { - return reject(err) - } - resolve({ - css, - imports - }) - }) - }) -} +module.exports = require('./dist/index.js').default +module.exports.default = module.exports diff --git a/packages/taro-plugin-stylus/jest.config.js b/packages/taro-plugin-stylus/jest.config.js new file mode 100644 index 000000000000..758fa1330e87 --- /dev/null +++ b/packages/taro-plugin-stylus/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +} diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index e36cab024b37..c03dfa385221 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,11 +1,22 @@ { "name": "@tarojs/plugin-stylus", "version": "2.2.7", - "description": "Taro 编译 stylus 文件", + "description": "Taro webpack stylus config plugin", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "npm run clean && npm run prod", + "dev": "tsc -w", + "prod": "tsc", + "clean": "rimraf dist", + "test": "jest", + "test:dev": "jest --watch" }, + "files": [ + "src", + "dist", + "index.js", + "package.json" + ], "repository": { "type": "git", "url": "git+https://github.com/NervJS/taro.git" @@ -16,6 +27,16 @@ "author": "luckyadam", "license": "MIT", "dependencies": { - "stylus": "^0.54.5" + "@tarojs/runner-utils": "2.2.7", + "@tarojs/service": "2.2.7", + "stylus": "0.54.7", + "stylus-loader": "3.0.2" + }, + "devDependencies": { + "@types/node": "^14.0.5", + "jest": "^26.0.1", + "rimraf": "^3.0.2", + "ts-jest": "^26.0.0", + "typescript": "^3.9.3" } } diff --git a/packages/taro-plugin-stylus/src/index.ts b/packages/taro-plugin-stylus/src/index.ts new file mode 100644 index 000000000000..1d89b2d54b73 --- /dev/null +++ b/packages/taro-plugin-stylus/src/index.ts @@ -0,0 +1,26 @@ +import { IPluginContext } from '@tarojs/service' + +export default (ctx: IPluginContext, opts) => { + ctx.modifyWebpackChain(async ({ chain }) => { + const { enableSourceMap = true } = opts + const taroEnv = process.env.TARO_ENV + if (taroEnv) { + const currentPlatform = ctx.platforms.get(taroEnv) + if (!currentPlatform) return + const platformConfig = ctx.initialConfig[currentPlatform.useConfigName] + const stylusLoaderOption = platformConfig.stylusLoaderOption + const defaultStylusLoaderOption = { + sourceMap: enableSourceMap + } + + chain.module + .rule('addChainStyleStylus') + .test(ctx.helper.REG_STYLUS) + .pre() + .use('stylus') + .loader(require.resolve('stylus-loader')) + .options(Object.assign({}, defaultStylusLoaderOption, stylusLoaderOption)) + .end() + } + }) +} diff --git a/packages/taro-plugin-stylus/tests/fixtures/base/style.styl b/packages/taro-plugin-stylus/tests/fixtures/base/style.styl deleted file mode 100644 index 5782580159a5..000000000000 --- a/packages/taro-plugin-stylus/tests/fixtures/base/style.styl +++ /dev/null @@ -1 +0,0 @@ -primary = #fff; \ No newline at end of file diff --git a/packages/taro-plugin-stylus/tests/fixtures/test.styl b/packages/taro-plugin-stylus/tests/fixtures/test.styl deleted file mode 100644 index 92b90534d6ef..000000000000 --- a/packages/taro-plugin-stylus/tests/fixtures/test.styl +++ /dev/null @@ -1,5 +0,0 @@ -@import 'style'; - -body { - color: primary; -} \ No newline at end of file diff --git a/packages/taro-plugin-stylus/tests/index.test.js b/packages/taro-plugin-stylus/tests/index.test.js deleted file mode 100644 index 09e5b7699386..000000000000 --- a/packages/taro-plugin-stylus/tests/index.test.js +++ /dev/null @@ -1,12 +0,0 @@ -const compile = require('../index') -const assert = require('assert') -const path = require('path') - -const file = path.join(__dirname, 'fixtures', 'test.styl') -// eslint-disable-next-line no-debugger - -compile(null, file, { - paths: [path.join(__dirname, 'fixtures', 'base')] -}).then(({ css }) => { - assert.equal(css, 'body {\n color: #fff;\n}\n', 'ok') -}) diff --git a/packages/taro-plugin-stylus/tsconfig.json b/packages/taro-plugin-stylus/tsconfig.json new file mode 100644 index 000000000000..522fe3c86d15 --- /dev/null +++ b/packages/taro-plugin-stylus/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowJs": true, + "baseUrl": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "dist/", + "preserveConstEnums": true, + "removeComments": false, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": false, + "strictNullChecks": true, + "target": "es2015", + "traceResolution": false, + "types": ["jest"] + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/__tests__" + ] +} diff --git a/packages/taro-plugin-stylus/yarn.lock b/packages/taro-plugin-stylus/yarn.lock deleted file mode 100644 index 25b964444e1c..000000000000 --- a/packages/taro-plugin-stylus/yarn.lock +++ /dev/null @@ -1,113 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -amdefine@>=0.0.4: - version "1.0.1" - resolved "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" - -balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - -css-parse@1.7.x: - version "1.7.0" - resolved "https://registry.npmjs.org/css-parse/-/css-parse-1.7.0.tgz#321f6cf73782a6ff751111390fc05e2c657d8c9b" - -debug@*: - version "3.1.0" - resolved "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" - dependencies: - ms "2.0.0" - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - -glob@7.0.x: - version "7.0.6" - resolved "https://registry.npmjs.org/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a" - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.2" - once "^1.3.0" - path-is-absolute "^1.0.0" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.3" - resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" - -minimatch@^3.0.2: - version "3.0.4" - resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - dependencies: - brace-expansion "^1.1.7" - -minimist@0.0.8: - version "0.0.8" - resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" - -mkdirp@0.5.x: - version "0.5.1" - resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" - dependencies: - minimist "0.0.8" - -ms@2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - -sax@0.5.x: - version "0.5.8" - resolved "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1" - -source-map@0.1.x: - version "0.1.43" - resolved "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346" - dependencies: - amdefine ">=0.0.4" - -stylus@^0.54.5: - version "0.54.5" - resolved "https://registry.npmjs.org/stylus/-/stylus-0.54.5.tgz#42b9560931ca7090ce8515a798ba9e6aa3d6dc79" - dependencies: - css-parse "1.7.x" - debug "*" - glob "7.0.x" - mkdirp "0.5.x" - sax "0.5.x" - source-map "0.1.x" - -wrappy@1: - version "1.0.2" - resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From e5d4ac8a190669ed8aab37112ee1a9f96f99fa1d Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 28 May 2020 20:59:39 +0800 Subject: [PATCH 07/15] =?UTF-8?q?refactor:=20=E5=AE=8C=E6=88=90=20h5=20?= =?UTF-8?q?=E7=9A=84=E6=A0=B7=E5=BC=8F=E9=85=8D=E7=BD=AE=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/h5/index.ts | 11 ++- packages/taro-mini-runner/package.json | 1 - .../taro-mini-runner/src/webpack/chain.ts | 12 ++-- packages/taro-plugin-sass/package.json | 1 + packages/taro-plugin-sass/src/index.ts | 3 + packages/taro-webpack-runner/package.json | 8 --- .../src/__tests__/index-test.ts | 21 +----- .../src/config/dev.conf.ts | 18 ++--- .../src/config/prod.conf.ts | 25 +++---- packages/taro-webpack-runner/src/index.ts | 22 +++--- .../taro-webpack-runner/src/util/chain.ts | 70 +++++-------------- 11 files changed, 63 insertions(+), 129 deletions(-) diff --git a/packages/taro-cli/src/h5/index.ts b/packages/taro-cli/src/h5/index.ts index 7b4e262de16e..7921b37dad03 100644 --- a/packages/taro-cli/src/h5/index.ts +++ b/packages/taro-cli/src/h5/index.ts @@ -27,7 +27,9 @@ import { processTypeEnum, PROJECT_CONFIG, REG_SCRIPTS, - REG_TYPESCRIPT + REG_TYPESCRIPT, + createBabelRegister, + getModuleDefaultExport } from '@tarojs/helper' import { convertAstExpressionToVariable as toVar, @@ -93,9 +95,14 @@ class Compiler { isUi: boolean constructor (public appPath: string, entryFile?: string, isUi?: boolean) { + createBabelRegister({ + only: [ + filePath => filePath.indexOf(path.dirname(path.join(appPath, PROJECT_CONFIG))) >= 0 + ] + }) const projectConfig = recursiveMerge({ h5: defaultH5Config - }, require(resolveScriptPath(path.join(appPath, PROJECT_CONFIG)))(merge)) + }, getModuleDefaultExport(require(resolveScriptPath(path.join(appPath, PROJECT_CONFIG))))(merge)) this.projectConfig = projectConfig const sourceDir = projectConfig.sourceRoot || CONFIG.SOURCE_DIR this.sourceRoot = sourceDir diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json index da7426278d83..5158fdb67f12 100644 --- a/packages/taro-mini-runner/package.json +++ b/packages/taro-mini-runner/package.json @@ -33,7 +33,6 @@ "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { "@tarojs/helper": "^2.2.7", - "@tarojs/runner-utils": "^2.2.7", "@tarojs/taro": "^2.2.7", "@tarojs/transformer-wx": "^2.2.7", "babel-core": "^6.26.3", diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index 2f8d93973065..1609349250c9 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -212,11 +212,13 @@ export const getModule = (appPath: string, { const styleExtRegs = [/\.css$/] const rules = chain.module.rules.entries() - Object.keys(rules).forEach(item => { - if (/^addChainStyle/.test(item) && rules[item].get('test')) { - styleExtRegs.push(rules[item].get('test')) - } - }) + if (rules) { + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + } const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) const styleModuleReg = new RegExp(`(.*\.module).*${styleReg.source}`) diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index ee1068c487ee..117f1b371b4d 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -30,6 +30,7 @@ "@tarojs/runner-utils": "2.2.7", "@tarojs/service": "2.2.7", "node-sass": "4.14.1", + "resolve-url-loader": "3.1.1", "sass-loader": "8.0.2" }, "devDependencies": { diff --git a/packages/taro-plugin-sass/src/index.ts b/packages/taro-plugin-sass/src/index.ts index c9219b7393f3..9ece139842e5 100644 --- a/packages/taro-plugin-sass/src/index.ts +++ b/packages/taro-plugin-sass/src/index.ts @@ -27,6 +27,9 @@ export default (ctx: IPluginContext, opts) => { .rule('addChainStyleSass') .test(ctx.helper.REG_SASS) .pre() + .use('resolveUrl') + .loader(require.resolve('resolve-url-loader')) + .end() .use('sass') .loader(require.resolve('sass-loader')) .options(Object.assign({}, defaultSassLoaderOption, newSassLoaderOption)) diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index d984a8172892..49473dc08d40 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -32,8 +32,6 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/plugin-sass": "^2.2.7", - "@tarojs/runner-utils": "^2.2.7", "@tarojs/taro": "^2.2.7", "@tarojs/taro-h5": "^2.2.7", "autoprefixer": "8.6.4", @@ -51,8 +49,6 @@ "file-loader": "^4.0.0", "html-webpack-include-assets-plugin": "1.0.5", "html-webpack-plugin": "3.2.0", - "less": "3.0.4", - "less-loader": "4.1.0", "lodash": "4.17.13", "mini-css-extract-plugin": "^0.7.0", "opn": "5.3.0", @@ -62,11 +58,7 @@ "postcss-pxtransform": "^2.2.7", "resolve": "^2.0.0-next.0", "resolve-url-loader": "2.3.0", - "sass": "^1.23.1", - "sass-loader": "7.1.0", "style-loader": "0.21.0", - "stylus": "0.54.5", - "stylus-loader": "3.0.2", "uglifyjs-webpack-plugin": "1.2.4", "url-loader": "1.1.2", "webpack": "4.41.6", diff --git a/packages/taro-webpack-runner/src/__tests__/index-test.ts b/packages/taro-webpack-runner/src/__tests__/index-test.ts index d1de21d74e89..68cded77b55b 100644 --- a/packages/taro-webpack-runner/src/__tests__/index-test.ts +++ b/packages/taro-webpack-runner/src/__tests__/index-test.ts @@ -29,6 +29,7 @@ describe('Regs', () => { }) it('should get a correct webpackConfig.module object', () => { + const chain = {} const { rule } = getModule('', { staticDirectory: '', designWidth: 750, @@ -38,9 +39,6 @@ describe('Regs', () => { styleLoaderOption: {}, cssLoaderOption: {}, - lessLoaderOption: {}, - sassLoaderOption: {}, - stylusLoaderOption: {}, fontUrlLoaderOption: {}, imageUrlLoaderOption: {}, mediaUrlLoaderOption: {}, @@ -48,22 +46,7 @@ describe('Regs', () => { postcss: {}, babel: {} - }) - expect(rule.sass).toMatchObject({ - test: /\.(s[ac]ss)\b/, - enforce: 'pre', - use: expect.any(Array) - }) - expect(rule.less).toMatchObject({ - test: /\.less\b/, - enforce: 'pre', - use: expect.any(Array) - }) - expect(rule.styl).toMatchObject({ - test: /\.styl\b/, - enforce: 'pre', - use: expect.any(Array) - }) + }, chain) expect(rule.css).toMatchObject({ test: /\.(css|s[ac]ss|less|styl)\b/, oneOf: expect.any(Array) diff --git a/packages/taro-webpack-runner/src/config/dev.conf.ts b/packages/taro-webpack-runner/src/config/dev.conf.ts index a46afa62f259..0c7d9673f92f 100644 --- a/packages/taro-webpack-runner/src/config/dev.conf.ts +++ b/packages/taro-webpack-runner/src/config/dev.conf.ts @@ -14,12 +14,10 @@ import { processEnvOption } from '../util/chain' import { BuildConfig } from '../util/types' -import getBaseChain from './base.conf' const emptyObj = {} -export default function (appPath: string, config: Partial): any { - const chain = getBaseChain(appPath) +export default function (appPath: string, config: Partial, chain: any): any { const { alias = emptyObj, copy, @@ -42,9 +40,6 @@ export default function (appPath: string, config: Partial): any { env = emptyObj, styleLoaderOption = emptyObj, cssLoaderOption = emptyObj, - sassLoaderOption = emptyObj, - lessLoaderOption = emptyObj, - stylusLoaderOption = emptyObj, mediaUrlLoaderOption = emptyObj, fontUrlLoaderOption = emptyObj, imageUrlLoaderOption = emptyObj, @@ -90,7 +85,7 @@ export default function (appPath: string, config: Partial): any { const mode = 'development' - chain.merge({ + return { mode, devtool: getDevtool({ enableSourceMap, sourceMapType }), entry, @@ -108,9 +103,6 @@ export default function (appPath: string, config: Partial): any { styleLoaderOption, cssLoaderOption, - lessLoaderOption, - sassLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -119,12 +111,10 @@ export default function (appPath: string, config: Partial): any { postcss, babel, staticDirectory - }), + }, chain), plugin, optimization: { noEmitOnErrors: true } - }) - - return chain + } } diff --git a/packages/taro-webpack-runner/src/config/prod.conf.ts b/packages/taro-webpack-runner/src/config/prod.conf.ts index 5e565d505f9b..9ed13a096161 100644 --- a/packages/taro-webpack-runner/src/config/prod.conf.ts +++ b/packages/taro-webpack-runner/src/config/prod.conf.ts @@ -1,7 +1,7 @@ -import * as path from 'path'; +import * as path from 'path' import { get, mapValues, merge } from 'lodash' -import { addTrailingSlash, emptyObj } from '../util'; +import { addTrailingSlash, emptyObj } from '../util' import { getCopyWebpackPlugin, getCssoWebpackPlugin, @@ -13,12 +13,10 @@ import { getOutput, getUglifyPlugin, processEnvOption -} from '../util/chain'; -import { BuildConfig } from '../util/types'; -import getBaseChain from './base.conf'; +} from '../util/chain' +import { BuildConfig } from '../util/types' -export default function (appPath: string, config: Partial): any { - const chain = getBaseChain(appPath) +export default function (appPath: string, config: Partial, chain: any): any { const { alias = emptyObj, copy, @@ -41,9 +39,6 @@ export default function (appPath: string, config: Partial): any { env = emptyObj, styleLoaderOption = emptyObj, cssLoaderOption = emptyObj, - sassLoaderOption = emptyObj, - lessLoaderOption = emptyObj, - stylusLoaderOption = emptyObj, mediaUrlLoaderOption = emptyObj, fontUrlLoaderOption = emptyObj, imageUrlLoaderOption = emptyObj, @@ -111,7 +106,7 @@ export default function (appPath: string, config: Partial): any { ])) } - chain.merge({ + return { mode, devtool: getDevtool({ enableSourceMap, sourceMapType }), entry, @@ -129,9 +124,6 @@ export default function (appPath: string, config: Partial): any { styleLoaderOption, cssLoaderOption, - lessLoaderOption, - sassLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -140,7 +132,7 @@ export default function (appPath: string, config: Partial): any { postcss, babel, staticDirectory - }), + }, chain), plugin, optimization: { minimizer, @@ -148,6 +140,5 @@ export default function (appPath: string, config: Partial): any { name: false } } - }) - return chain + } } diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index cb0240ff4d70..8bdc0b2efcb4 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -6,12 +6,12 @@ import * as webpack from 'webpack' import * as WebpackDevServer from 'webpack-dev-server' import buildConf from './config/build.conf' import devConf from './config/dev.conf' +import baseConf from './config/base.conf' import baseDevServerOption from './config/devServer.conf' import prodConf from './config/prod.conf' import { addLeadingSlash, addTrailingSlash, recursiveMerge, formatOpenHost } from './util' import { bindDevLogger, bindProdLogger, printBuildError } from './util/logHelper' import { BuildConfig } from './util/types' -import { makeConfig } from './util/chain' const stripTrailingSlash = (path: string): string => path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path @@ -35,8 +35,10 @@ const customizeChain = async (chain, modifyWebpackChainFunc: Function, customize } const buildProd = async (appPath: string, config: BuildConfig): Promise => { - const webpackChain = prodConf(appPath, config) - await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + const baseWebpackChain = baseConf(appPath) + await customizeChain(baseWebpackChain, config.modifyWebpackChain, config.webpackChain) + const prodWebpackConf = prodConf(appPath, config, baseWebpackChain) + const webpackChain = baseWebpackChain.merge(prodWebpackConf) const webpackConfig = webpackChain.toConfig() const compiler = webpack(webpackConfig) const onBuildFinish = config.onBuildFinish @@ -80,11 +82,12 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise => { const publicPath = conf.publicPath ? addLeadingSlash(addTrailingSlash(conf.publicPath)) : '/' const outputPath = path.join(appPath, conf.outputRoot as string) const customDevServerOption = config.devServer || {} - const webpackChain = devConf(appPath, config) const homePage = config.homePage || [] const onBuildFinish = config.onBuildFinish - - await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + const baseWebpackChain = baseConf(appPath) + await customizeChain(baseWebpackChain, config.modifyWebpackChain, config.webpackChain) + const devWebpackConf = devConf(appPath, config, baseWebpackChain) + const webpackChain = baseWebpackChain.merge(devWebpackConf) const devServerOptions = recursiveMerge( { @@ -179,16 +182,15 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise => { } export default async (appPath: string, config: BuildConfig): Promise => { - const newConfig: BuildConfig = await makeConfig(config) - if (newConfig.isWatch) { + if (config.isWatch) { try { - await buildDev(appPath, newConfig) + await buildDev(appPath, config) } catch (e) { console.error(e) } } else { try { - await buildProd(appPath, newConfig) + await buildProd(appPath, config) } catch (e) { console.error(e) process.exit(1); diff --git a/packages/taro-webpack-runner/src/util/chain.ts b/packages/taro-webpack-runner/src/util/chain.ts index a32f7423e617..dd15e94fd673 100644 --- a/packages/taro-webpack-runner/src/util/chain.ts +++ b/packages/taro-webpack-runner/src/util/chain.ts @@ -1,8 +1,6 @@ import * as apis from '@tarojs/taro-h5/dist/taroApis' -import { getSassLoaderOption } from '@tarojs/runner-utils' import * as CopyWebpackPlugin from 'copy-webpack-plugin' import CssoWebpackPlugin from 'csso-webpack-plugin' -import * as sass from 'sass' import * as HtmlWebpackPlugin from 'html-webpack-plugin' import { partial } from 'lodash' import { mapKeys, pipe } from 'lodash/fp' @@ -14,15 +12,7 @@ import { PostcssOption, IPostcssOption, ICopyOptions } from '@tarojs/taro/types/ import { recursiveMerge } from '.' import { getPostcssPlugins } from '../config/postcss.conf' -import { Option, BuildConfig } from './types' - -const makeConfig = async (buildConfig: BuildConfig) => { - const sassLoaderOption: Option = await getSassLoaderOption(buildConfig) - return { - ...buildConfig, - sassLoaderOption - } -} +import { Option } from './types' const defaultUglifyJsOption = { keep_fnames: true, @@ -107,10 +97,6 @@ const processEnvOption = partial(mapKeys, key => `process.env.${key}`) const getStyleLoader = pipe(mergeOption, partial(getLoader, 'style-loader')) const getCssLoader = pipe(mergeOption, partial(getLoader, 'css-loader')) const getPostcssLoader = pipe(mergeOption, partial(getLoader, 'postcss-loader')) -const getResolveUrlLoader = pipe(mergeOption, partial(getLoader, 'resolve-url-loader')) -const getSassLoader = pipe(mergeOption, partial(getLoader, 'sass-loader')) -const getLessLoader = pipe(mergeOption, partial(getLoader, 'less-loader')) -const getStylusLoader = pipe(mergeOption, partial(getLoader, 'stylus-loader')) const getBabelLoader = pipe(mergeOption, partial(getLoader, 'babel-loader')) const getUrlLoader = pipe(mergeOption, partial(getLoader, 'url-loader')) const getExtractCssLoader = () => { @@ -151,12 +137,6 @@ const getCopyWebpackPlugin = ({ copy, appPath }: { return partial(getPlugin, CopyWebpackPlugin)(args) } -const sassReg = /\.(s[ac]ss)\b/ -const lessReg = /\.less\b/ -const stylReg = /\.styl\b/ -const styleReg = /\.(css|s[ac]ss|less|styl)\b/ -const styleModuleReg = /(.*\.module).*\.(css|s[ac]ss|less|styl)\b/ -const styleGlobalReg = /(.*\.global).*\.(css|s[ac]ss|less|styl)\b/ const jsxReg = /\.jsx?$/ const mediaReg = /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/ const fontReg = /\.(woff2?|eot|ttf|otf)(\?.*)?$/ @@ -191,9 +171,6 @@ const getModule = (appPath: string, { styleLoaderOption, cssLoaderOption, - lessLoaderOption, - sassLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -201,7 +178,7 @@ const getModule = (appPath: string, { postcss, babel -}) => { +}, chain) => { const postcssOption: IPostcssOption = postcss || {} const defaultStyleLoaderOption = { @@ -288,6 +265,20 @@ const getModule = (appPath: string, { use: [cssLoader] }] + const styleExtRegs = [/\.css$/] + const rules = chain.module.rules.entries() + if (rules) { + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + } + const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) + + const styleModuleReg = new RegExp(`(.*\.module).*${styleReg.source}`) + const styleGlobalReg = new RegExp(`(.*\.global).*${styleReg.source}`) + if (cssModuleOptions.enable) { const cssLoaderWithModule = getCssLoader(cssOptionsWithModule) let cssModuleCondition @@ -321,36 +312,10 @@ const getModule = (appPath: string, { } ]) - const resolveUrlLoader = getResolveUrlLoader([]) - - const sassLoader = getSassLoader([{ - sourceMap: true, - implementation: sass - }, sassLoaderOption]) - - const lessLoader = getLessLoader([{ sourceMap: enableSourceMap }, lessLoaderOption]) - - const stylusLoader = getStylusLoader([{ sourceMap: enableSourceMap }, stylusLoaderOption]) - const rule: { [key: string]: any } = {} - rule.sass = { - test: sassReg, - enforce: 'pre', - use: [resolveUrlLoader, sassLoader] - } - rule.less = { - test: lessReg, - enforce: 'pre', - use: [lessLoader] - } - rule.styl = { - test: stylReg, - enforce: 'pre', - use: [stylusLoader] - } rule.css = { test: styleReg, oneOf: cssLoaders @@ -434,8 +399,7 @@ const getDevtool = ({ enableSourceMap, sourceMapType }) => { export { isNodeModule, isTaroModule, - getEsnextModuleRules, - makeConfig + getEsnextModuleRules } export { getOutput, getMiniCssExtractPlugin, getHtmlWebpackPlugin, getDefinePlugin, processEnvOption, getHotModuleReplacementPlugin, getModule, getUglifyPlugin, getDevtool, getCssoWebpackPlugin, getCopyWebpackPlugin } From 7145cb2c6510373c6c0e01492eed75476b3919a5 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Sat, 30 May 2020 17:58:35 +0800 Subject: [PATCH 08/15] =?UTF-8?q?refactor:=20uglify=20&&=20terser=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lerna.json | 3 +- .../src/webpack/build.conf.ts | 13 ------ .../taro-mini-runner/src/webpack/chain.ts | 19 --------- packages/taro-plugin-terser/index.js | 2 + packages/taro-plugin-terser/jest.config.js | 4 ++ packages/taro-plugin-terser/package.json | 41 +++++++++++++++++++ packages/taro-plugin-terser/src/index.ts | 37 +++++++++++++++++ packages/taro-plugin-terser/tsconfig.json | 29 +++++++++++++ packages/taro-plugin-uglify/index.js | 2 + packages/taro-plugin-uglify/jest.config.js | 4 ++ packages/taro-plugin-uglify/package.json | 41 +++++++++++++++++++ packages/taro-plugin-uglify/src/index.ts | 37 +++++++++++++++++ packages/taro-plugin-uglify/tsconfig.json | 29 +++++++++++++ packages/taro-plugin-uglifyjs/index.js | 5 --- packages/taro-plugin-uglifyjs/package.json | 21 ---------- packages/taro-plugin-uglifyjs/yarn.lock | 18 -------- 16 files changed, 228 insertions(+), 77 deletions(-) create mode 100644 packages/taro-plugin-terser/index.js create mode 100644 packages/taro-plugin-terser/jest.config.js create mode 100644 packages/taro-plugin-terser/package.json create mode 100644 packages/taro-plugin-terser/src/index.ts create mode 100644 packages/taro-plugin-terser/tsconfig.json create mode 100644 packages/taro-plugin-uglify/index.js create mode 100644 packages/taro-plugin-uglify/jest.config.js create mode 100644 packages/taro-plugin-uglify/package.json create mode 100644 packages/taro-plugin-uglify/src/index.ts create mode 100644 packages/taro-plugin-uglify/tsconfig.json delete mode 100644 packages/taro-plugin-uglifyjs/index.js delete mode 100644 packages/taro-plugin-uglifyjs/package.json delete mode 100644 packages/taro-plugin-uglifyjs/yarn.lock diff --git a/lerna.json b/lerna.json index ca4b16e490c8..5292257f25b0 100644 --- a/lerna.json +++ b/lerna.json @@ -12,7 +12,8 @@ "packages/taro-plugin-babel", "packages/taro-plugin-csso", "packages/taro-plugin-sass", - "packages/taro-plugin-uglifyjs", + "packages/taro-plugin-terser", + "packages/taro-plugin-uglify", "packages/taro-plugin-typescript", "packages/taro-plugin-less", "packages/taro-plugin-stylus", diff --git a/packages/taro-mini-runner/src/webpack/build.conf.ts b/packages/taro-mini-runner/src/webpack/build.conf.ts index 2258846edec7..dd5138832a83 100644 --- a/packages/taro-mini-runner/src/webpack/build.conf.ts +++ b/packages/taro-mini-runner/src/webpack/build.conf.ts @@ -8,7 +8,6 @@ import { getDefinePlugin, processEnvOption, getCssoWebpackPlugin, - getUglifyPlugin, getDevtool, getOutput, getModule, @@ -58,7 +57,6 @@ export default (appPath: string, mode, config: Partial, chain: any babel, csso, - uglify, commonChunks, addChunkPages, @@ -131,18 +129,7 @@ export default (appPath: string, mode, config: Partial, chain: any ? false : true - const isUglifyEnabled = (uglify && uglify.enable === false) - ? false - : true - if (mode === 'production') { - if (isUglifyEnabled) { - minimizer.push(getUglifyPlugin([ - enableSourceMap, - uglify ? uglify.config : {} - ])) - } - if (isCssoEnabled) { const cssoConfig: any = csso ? csso.config : {} plugin.cssoWebpackPlugin = getCssoWebpackPlugin([cssoConfig]) diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index 1609349250c9..fb7bd1f56d14 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -6,7 +6,6 @@ import CssoWebpackPlugin from 'csso-webpack-plugin' import * as MiniCssExtractPlugin from 'mini-css-extract-plugin' import { partial } from 'lodash' import { mapKeys, pipe } from 'lodash/fp' -import * as UglifyJsPlugin from 'uglifyjs-webpack-plugin' import * as webpack from 'webpack' import { PostcssOption, ICopyOptions, IPostcssOption } from '@tarojs/taro/types/compile' import { @@ -27,16 +26,6 @@ import { getPostcssPlugins } from './postcss.conf' import MiniPlugin from '../plugins/MiniPlugin' import { IOption } from '../utils/types' -const defaultUglifyJsOption = { - keep_fnames: true, - output: { - comments: false, - keep_quoted_props: true, - quote_keys: true, - beautify: false - }, - warnings: false -} const defaultCSSCompressOption = { mergeRules: false, mergeIdents: false, @@ -108,14 +97,6 @@ const getQuickappStyleLoader = () => { } export const getMiniCssExtractPlugin = pipe(mergeOption, listify, partial(getPlugin, MiniCssExtractPlugin)) export const getDefinePlugin = pipe(mergeOption, listify, partial(getPlugin, webpack.DefinePlugin)) -export const getUglifyPlugin = ([enableSourceMap, uglifyOptions]) => { - return new UglifyJsPlugin({ - cache: true, - parallel: true, - sourceMap: enableSourceMap, - uglifyOptions: recursiveMerge({}, defaultUglifyJsOption, uglifyOptions) - }) -} export const getCssoWebpackPlugin = ([cssoOption]) => { return pipe(listify, partial(getPlugin, CssoWebpackPlugin))([mergeOption([defaultCSSCompressOption, cssoOption]), REG_STYLE]) } diff --git a/packages/taro-plugin-terser/index.js b/packages/taro-plugin-terser/index.js new file mode 100644 index 000000000000..437a6d4788f4 --- /dev/null +++ b/packages/taro-plugin-terser/index.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/index.js').default +module.exports.default = module.exports diff --git a/packages/taro-plugin-terser/jest.config.js b/packages/taro-plugin-terser/jest.config.js new file mode 100644 index 000000000000..758fa1330e87 --- /dev/null +++ b/packages/taro-plugin-terser/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +} diff --git a/packages/taro-plugin-terser/package.json b/packages/taro-plugin-terser/package.json new file mode 100644 index 000000000000..ded1eb9575de --- /dev/null +++ b/packages/taro-plugin-terser/package.json @@ -0,0 +1,41 @@ +{ + "name": "@tarojs/plugin-terser", + "version": "2.2.7", + "description": "Taro webpack terser config plugin", + "main": "index.js", + "scripts": { + "build": "npm run clean && npm run prod", + "dev": "tsc -w", + "prod": "tsc", + "clean": "rimraf dist", + "test": "jest", + "test:dev": "jest --watch" + }, + "files": [ + "src", + "dist", + "index.js", + "package.json" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/NervJS/taro.git" + }, + "keywords": [ + "taro" + ], + "author": "luckyadam", + "license": "MIT", + "dependencies": { + "@tarojs/runner-utils": "2.2.7", + "@tarojs/service": "2.2.7", + "terser-webpack-plugin": "3.0.2" + }, + "devDependencies": { + "@types/node": "^14.0.5", + "jest": "^26.0.1", + "rimraf": "^3.0.2", + "ts-jest": "^26.0.0", + "typescript": "^3.9.3" + } +} diff --git a/packages/taro-plugin-terser/src/index.ts b/packages/taro-plugin-terser/src/index.ts new file mode 100644 index 000000000000..204d928182a5 --- /dev/null +++ b/packages/taro-plugin-terser/src/index.ts @@ -0,0 +1,37 @@ +import { IPluginContext } from '@tarojs/service' + +export default (ctx: IPluginContext, opts) => { + ctx.modifyWebpackChain(async ({ chain }) => { + const { enableSourceMap = true } = opts + const { recursiveMerge } = ctx.helper + const TerserPlugin = require('terser-webpack-plugin') + const defaultTerserOption = { + keep_fnames: true, + output: { + comments: false, + keep_quoted_props: true, + quote_keys: true, + beautify: false + }, + warnings: false + } + const terser = ctx.initialConfig.terser + const isTerserEnabled = (terser && terser.enable === false) + ? false + : true + if (isTerserEnabled) { + chain.merge({ + optimization: { + minimizer: [ + new TerserPlugin({ + cache: true, + parallel: true, + sourceMap: enableSourceMap, + terserOptions: recursiveMerge({}, defaultTerserOption, terser ? terser.config || {} : {}) + }) + ] + } + }) + } + }) +} diff --git a/packages/taro-plugin-terser/tsconfig.json b/packages/taro-plugin-terser/tsconfig.json new file mode 100644 index 000000000000..522fe3c86d15 --- /dev/null +++ b/packages/taro-plugin-terser/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowJs": true, + "baseUrl": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "dist/", + "preserveConstEnums": true, + "removeComments": false, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": false, + "strictNullChecks": true, + "target": "es2015", + "traceResolution": false, + "types": ["jest"] + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/__tests__" + ] +} diff --git a/packages/taro-plugin-uglify/index.js b/packages/taro-plugin-uglify/index.js new file mode 100644 index 000000000000..437a6d4788f4 --- /dev/null +++ b/packages/taro-plugin-uglify/index.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/index.js').default +module.exports.default = module.exports diff --git a/packages/taro-plugin-uglify/jest.config.js b/packages/taro-plugin-uglify/jest.config.js new file mode 100644 index 000000000000..758fa1330e87 --- /dev/null +++ b/packages/taro-plugin-uglify/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +} diff --git a/packages/taro-plugin-uglify/package.json b/packages/taro-plugin-uglify/package.json new file mode 100644 index 000000000000..751c73a7074b --- /dev/null +++ b/packages/taro-plugin-uglify/package.json @@ -0,0 +1,41 @@ +{ + "name": "@tarojs/plugin-uglify", + "version": "2.2.7", + "description": "Taro webpack uglify config plugin", + "main": "index.js", + "scripts": { + "build": "npm run clean && npm run prod", + "dev": "tsc -w", + "prod": "tsc", + "clean": "rimraf dist", + "test": "jest", + "test:dev": "jest --watch" + }, + "files": [ + "src", + "dist", + "index.js", + "package.json" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/NervJS/taro.git" + }, + "keywords": [ + "taro" + ], + "author": "luckyadam", + "license": "MIT", + "dependencies": { + "@tarojs/runner-utils": "2.2.7", + "@tarojs/service": "2.2.7", + "uglifyjs-webpack-plugin": "2.2.0" + }, + "devDependencies": { + "@types/node": "^14.0.5", + "jest": "^26.0.1", + "rimraf": "^3.0.2", + "ts-jest": "^26.0.0", + "typescript": "^3.9.3" + } +} diff --git a/packages/taro-plugin-uglify/src/index.ts b/packages/taro-plugin-uglify/src/index.ts new file mode 100644 index 000000000000..c27fb9987e0f --- /dev/null +++ b/packages/taro-plugin-uglify/src/index.ts @@ -0,0 +1,37 @@ +import { IPluginContext } from '@tarojs/service' + +export default (ctx: IPluginContext, opts) => { + ctx.modifyWebpackChain(async ({ chain }) => { + const { enableSourceMap = true } = opts + const { recursiveMerge } = ctx.helper + const UglifyJsPlugin = require('uglifyjs-webpack-plugin') + const defaultUglifyJsOption = { + keep_fnames: true, + output: { + comments: false, + keep_quoted_props: true, + quote_keys: true, + beautify: false + }, + warnings: false + } + const uglify = ctx.initialConfig.uglify + const isUglifyEnabled = (uglify && uglify.enable === false) + ? false + : true + if (isUglifyEnabled) { + chain.merge({ + optimization: { + minimizer: [ + new UglifyJsPlugin({ + cache: true, + parallel: true, + sourceMap: enableSourceMap, + uglifyOptions: recursiveMerge({}, defaultUglifyJsOption, uglify ? uglify.config || {} : {}) + }) + ] + } + }) + } + }) +} diff --git a/packages/taro-plugin-uglify/tsconfig.json b/packages/taro-plugin-uglify/tsconfig.json new file mode 100644 index 000000000000..522fe3c86d15 --- /dev/null +++ b/packages/taro-plugin-uglify/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowJs": true, + "baseUrl": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "dist/", + "preserveConstEnums": true, + "removeComments": false, + "rootDir": "./src", + "skipLibCheck": true, + "sourceMap": false, + "strictNullChecks": true, + "target": "es2015", + "traceResolution": false, + "types": ["jest"] + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/__tests__" + ] +} diff --git a/packages/taro-plugin-uglifyjs/index.js b/packages/taro-plugin-uglifyjs/index.js deleted file mode 100644 index 6b0359382e5b..000000000000 --- a/packages/taro-plugin-uglifyjs/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const uglifyJS = require('uglify-js') - -module.exports = function uglify (content, file, config) { - return uglifyJS.minify(content, config) -} diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json deleted file mode 100644 index b5942aafc068..000000000000 --- a/packages/taro-plugin-uglifyjs/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@tarojs/plugin-uglifyjs", - "version": "2.2.7", - "description": "Taro压缩JS文件", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/NervJS/taro.git" - }, - "keywords": [ - "taro" - ], - "author": "luckyadam", - "license": "MIT", - "dependencies": { - "uglify-js": "^3.3.24" - } -} diff --git a/packages/taro-plugin-uglifyjs/yarn.lock b/packages/taro-plugin-uglifyjs/yarn.lock deleted file mode 100644 index 3cb05107a3e2..000000000000 --- a/packages/taro-plugin-uglifyjs/yarn.lock +++ /dev/null @@ -1,18 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -commander@~2.15.0: - version "2.15.1" - resolved "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" - -source-map@~0.6.1: - version "0.6.1" - resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" - -uglify-js@^3.3.24: - version "3.3.24" - resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.24.tgz#abeae7690c602ebd006f4567387a0c0c333bdc0d" - dependencies: - commander "~2.15.0" - source-map "~0.6.1" From 26c2bcf839008c7e0bbfcc20d0ba7083b1a95b69 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 3 Jun 2020 16:28:11 +0800 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20rn-runner=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=86=85=E7=BD=AE=E7=9A=84=20sass/less/stylus/uglify?= =?UTF-8?q?=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/package.json | 1 - packages/taro-rn-runner/package.json | 6 -- packages/taro-rn-runner/src/index.ts | 21 ++---- .../taro-rn-runner/src/webpack/build.conf.ts | 28 ++------ packages/taro-rn-runner/src/webpack/chain.ts | 70 ++++++------------- packages/taro-webpack-runner/package.json | 1 - 6 files changed, 31 insertions(+), 96 deletions(-) diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json index 5158fdb67f12..18d90124853c 100644 --- a/packages/taro-mini-runner/package.json +++ b/packages/taro-mini-runner/package.json @@ -62,7 +62,6 @@ "request": "^2.88.0", "resolve": "^2.0.0-next.0", "sax": "^1.2.4", - "uglifyjs-webpack-plugin": "^2.2.0", "url-loader": "^2.0.0", "webpack": "4.41.6", "webpack-chain": "4.9.0", diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index b1222d15e418..27c7fb5fa066 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -53,12 +53,9 @@ "fbjs": "^1.0.0", "file-loader": "^4.0.0", "fs-extra": "^8.0.1", - "less": "^3.10.3", - "less-loader": "^5.0.0", "loader-utils": "^1.2.3", "lodash": "^4.17.11", "mini-css-extract-plugin": "^0.7.0", - "node-sass": "^4.12.0", "ora": "^3.4.0", "postcss-loader": "^3.0.0", "postcss-pxtransform": "2.0.4", @@ -66,17 +63,14 @@ "postcss-url": "^8.0.0", "request": "^2.88.0", "resolve": "^2.0.0-next.0", - "sass-loader": "^7.1.0", "sax": "^1.2.4", "scss-bundle": "^2.5.1", "stats-webpack-plugin": "^0.7.0", "stylelint": "^9.3.0", "stylelint-config-taro-rn": "^2.2.7", "stylelint-taro-rn": "^2.2.7", - "stylus-loader": "^3.0.2", "tapable": "1.1.3", "taro-css-to-react-native": "^2.2.7", - "uglifyjs-webpack-plugin": "^2.2.0", "url-loader": "^2.0.0", "webpack": "4.41.6", "webpack-chain": "4.9.0", diff --git a/packages/taro-rn-runner/src/index.ts b/packages/taro-rn-runner/src/index.ts index 009ae22f288e..b98b162cc856 100644 --- a/packages/taro-rn-runner/src/index.ts +++ b/packages/taro-rn-runner/src/index.ts @@ -1,9 +1,9 @@ import * as webpack from 'webpack' -import { getSassLoaderOption } from '@tarojs/runner-utils' -import { IBuildConfig, IOption } from './utils/types' +import { IBuildConfig } from './utils/types' import { PARSE_AST_TYPE } from './utils/constants' import { printBuildError, bindProdLogger, bindDevLogger } from './utils/logHelper' +import baseConf from './webpack/base.conf' import buildConf from './webpack/build.conf' const customizeChain = async (chain, modifyWebpackChainFunc: Function, customizeFunc: Function) => { @@ -15,20 +15,13 @@ const customizeChain = async (chain, modifyWebpackChainFunc: Function, customize } } -const makeConfig = async (buildConfig: IBuildConfig) => { - const sassLoaderOption: IOption = await getSassLoaderOption(buildConfig) - return { - ...buildConfig, - sassLoaderOption - } -} - -export default async function build (appPath: string, config: IBuildConfig, mainBuilder) { +export default async function build (appPath: string, config: IBuildConfig) { const mode = config.mode - const newConfig = await makeConfig(config) + const baseWebpackChain = baseConf(appPath) // config.webpackChain 自定义 Webpack 配置,接受函数形式的配置。 - const webpackChain = buildConf(appPath, mode, config) - await customizeChain(webpackChain, newConfig.modifyWebpackChain, newConfig.webpackChain) + await customizeChain(baseWebpackChain, config.modifyWebpackChain, config.webpackChain) + const buildWebpackConf = buildConf(appPath, mode, config, baseWebpackChain) + const webpackChain = baseWebpackChain.merge(buildWebpackConf) const webpackConfig = webpackChain.toConfig() webpackConfig.stats = 'verbose' webpackConfig.profile = true diff --git a/packages/taro-rn-runner/src/webpack/build.conf.ts b/packages/taro-rn-runner/src/webpack/build.conf.ts index bc9c29ed1c50..8d91b90fc3f7 100644 --- a/packages/taro-rn-runner/src/webpack/build.conf.ts +++ b/packages/taro-rn-runner/src/webpack/build.conf.ts @@ -8,7 +8,6 @@ import { // getStatsPlugin, processEnvOption, getCssoWebpackPlugin, - getUglifyPlugin, getDevtool, getOutput, getModule, @@ -17,7 +16,6 @@ import { getMiniCssExtractPlugin, getEntry } from './chain' -import getBaseConf from './base.conf' import { BUILD_TYPES } from '../utils/constants' import { Targets } from '../plugins/RNPlugin' @@ -25,8 +23,7 @@ const nodeExternals = require('webpack-node-externals') const emptyObj = {} -export default (appPath: string, mode, config: Partial): any => { - const chain = getBaseConf(appPath) +export default (appPath: string, mode, config: Partial, chain: any): any => { const { buildAdapter = BUILD_TYPES.WEAPP, alias = emptyObj, @@ -42,9 +39,6 @@ export default (appPath: string, mode, config: Partial): any => { defineConstants = emptyObj, env = emptyObj, cssLoaderOption = emptyObj, - sassLoaderOption = emptyObj, - lessLoaderOption = emptyObj, - stylusLoaderOption = emptyObj, mediaUrlLoaderOption = emptyObj, fontUrlLoaderOption = emptyObj, imageUrlLoaderOption = emptyObj, @@ -57,7 +51,6 @@ export default (appPath: string, mode, config: Partial): any => { babel, csso, - uglify, commonChunks, // @ts-ignore addChunkPages, @@ -132,23 +125,14 @@ export default (appPath: string, mode, config: Partial): any => { const isCssoEnabled = !(csso && csso.enable === false) - const isUglifyEnabled = !(uglify && uglify.enable === false) - // not use if (mode === 'production') { - if (isUglifyEnabled) { - minimizer.push(getUglifyPlugin([ - enableSourceMap, - uglify ? uglify.config : {} - ])) - } - if (isCssoEnabled) { const cssoConfig: any = csso ? csso.config : {} plugin.cssoWebpackPlugin = getCssoWebpackPlugin([cssoConfig]) } } - chain.merge({ + return { mode, devtool: getDevtool(enableSourceMap), watch: mode === 'development', @@ -177,9 +161,6 @@ export default (appPath: string, mode, config: Partial): any => { enableSourceMap, cssLoaderOption, - lessLoaderOption, - sassLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -188,7 +169,7 @@ export default (appPath: string, mode, config: Partial): any => { compile, babel, alias - }), + }, chain), plugin, optimization: { minimizer, @@ -205,6 +186,5 @@ export default (appPath: string, mode, config: Partial): any => { // } // } } - }) - return chain + } } diff --git a/packages/taro-rn-runner/src/webpack/chain.ts b/packages/taro-rn-runner/src/webpack/chain.ts index 6f90d951fc37..bbc91d34d1fc 100644 --- a/packages/taro-rn-runner/src/webpack/chain.ts +++ b/packages/taro-rn-runner/src/webpack/chain.ts @@ -4,10 +4,8 @@ import { ProvidePlugin } from 'webpack' import * as CopyWebpackPlugin from 'copy-webpack-plugin' import CssoWebpackPlugin from 'csso-webpack-plugin' import * as MiniCssExtractPlugin from 'mini-css-extract-plugin' -import * as sass from 'node-sass' import { partial } from 'lodash' import { mapKeys, pipe } from 'lodash/fp' -import * as UglifyJsPlugin from 'uglifyjs-webpack-plugin' import * as webpack from 'webpack' import { PostcssOption, ICopyOptions, IPostcssOption } from '@tarojs/taro/types/compile' import chalk from 'chalk' @@ -18,9 +16,6 @@ import RNPlugin from '../plugins/RNPlugin' import { IOption } from '../utils/types' import { recursiveMerge, isNodeModule, resolveScriptPath } from '../utils' import { - REG_SASS, - REG_LESS, - REG_STYLUS, REG_STYLE, REG_MEDIA, REG_FONT, @@ -104,16 +99,10 @@ export const mergeOption = ([...options]: IOption[]): IOption => { return recursiveMerge({}, ...options) } -const styleModuleReg = /(.*\.module).*\.(css|s[ac]ss|less|styl)\b/ -const styleGlobalReg = /(.*\.global).*\.(css|s[ac]ss|less|styl)\b/ - export const processEnvOption = partial(mapKeys as any, (key: string) => `process.env.${key}`) as any export const getCssLoader = pipe(mergeOption, partial(getLoader, 'css-loader')) export const getPostcssLoader = pipe(mergeOption, partial(getLoader, 'postcss-loader')) -export const getSassLoader = pipe(mergeOption, partial(getLoader, 'sass-loader')) -export const getLessLoader = pipe(mergeOption, partial(getLoader, 'less-loader')) -export const getStylusLoader = pipe(mergeOption, partial(getLoader, 'stylus-loader')) export const getUrlLoader = pipe(mergeOption, partial(getLoader, 'url-loader')) export const getFileLoader = pipe(mergeOption, partial(getLoader, 'file-loader')) export const getFileParseLoader = pipe(mergeOption, partial(getLoader, path.resolve(__dirname, '../loaders/fileParseLoader'))) @@ -127,14 +116,7 @@ const getExtractCssLoader = () => { } export const getMiniCssExtractPlugin = pipe(mergeOption, listify, partial(getPlugin, MiniCssExtractPlugin)) export const getDefinePlugin = pipe(mergeOption, listify, partial(getPlugin, webpack.DefinePlugin)) -export const getUglifyPlugin = ([enableSourceMap, uglifyOptions]) => { - return new UglifyJsPlugin({ - cache: true, - parallel: true, - sourceMap: enableSourceMap, - uglifyOptions: recursiveMerge({}, defaultUglifyJsOption, uglifyOptions) - }) -} + export const getCssoWebpackPlugin = ([cssoOption]) => { return pipe(listify, partial(getPlugin, CssoWebpackPlugin))([mergeOption([defaultCSSCompressOption, cssoOption]), REG_STYLE]) } @@ -179,9 +161,6 @@ export const getModule = (appPath: string, { enableSourceMap, cssLoaderOption, - lessLoaderOption, - sassLoaderOption, - stylusLoaderOption, fontUrlLoaderOption, imageUrlLoaderOption, mediaUrlLoaderOption, @@ -189,7 +168,7 @@ export const getModule = (appPath: string, { compile, babel, alias -}) => { +}, chain) => { const postcssOption: IPostcssOption = postcss || {} const cssModuleOptions: PostcssOption.cssModules = recursiveMerge({}, defaultCssModuleOption, postcssOption.cssModules) @@ -245,6 +224,20 @@ export const getModule = (appPath: string, { const compileExclude = compile.exclude || [] const compileInclude = compile.include || [] + const styleExtRegs = [/\.css$/] + const rules = chain.module.rules.entries() + if (rules) { + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + } + const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) + + const styleModuleReg = new RegExp(`(.*\.module).*${styleReg.source}`) + const styleGlobalReg = new RegExp(`(.*\.global).*${styleReg.source}`) + if (cssModuleOptions.enable) { const cssLoaderWithModule = getCssLoader(cssOptionsWithModule) let cssModuleCondition @@ -277,14 +270,6 @@ export const getModule = (appPath: string, { }) } ]) - const sassLoader = getSassLoader([ - { - sourceMap: true, - implementation: sass - }, sassLoaderOption]) - const lessLoader = getLessLoader([{sourceMap: enableSourceMap}, lessLoaderOption]) - - const stylusLoader = getStylusLoader([{sourceMap: enableSourceMap}, stylusLoaderOption]) // const fileLoader = getFileLoader([ // { @@ -345,36 +330,21 @@ export const getModule = (appPath: string, { } const rule: any = { - sass: { - test: REG_SASS, - enforce: 'pre', - use: [sassLoader] - }, - less: { - test: REG_LESS, - enforce: 'pre', - use: [lessLoader] - }, - stylus: { - test: REG_STYLUS, - enforce: 'pre', - use: [stylusLoader] - }, css: { - test: REG_STYLE, + test: styleReg, oneOf: cssLoaders }, // styleFiles: { - // test: REG_STYLE, + // test: styleReg, // use: [fileLoader] // }, postcss: { - test: REG_STYLE, + test: styleReg, use: [postcssLoader] }, // miniCssExtractPlugin customStyle: { - test: REG_STYLE, + test: styleReg, enforce: 'post', use: [extractCssLoader] }, diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index 49473dc08d40..42a76e19f28d 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -59,7 +59,6 @@ "resolve": "^2.0.0-next.0", "resolve-url-loader": "2.3.0", "style-loader": "0.21.0", - "uglifyjs-webpack-plugin": "1.2.4", "url-loader": "1.1.2", "webpack": "4.41.6", "webpack-chain": "4.9.0", From 70070987d57a618a1f5c3c9de45581ab5c7a38ca Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 3 Jun 2020 17:25:28 +0800 Subject: [PATCH 10/15] =?UTF-8?q?feat(service):=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=A2=9E=E5=8A=A0=20name=20=E6=9D=A5?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E9=80=9A=E8=BF=87=20npm=20=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=9A=84=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-service/src/utils/index.ts | 15 +++++++++++---- packages/taro-service/src/utils/types.ts | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/taro-service/src/utils/index.ts b/packages/taro-service/src/utils/index.ts index 76fd62184623..f6fe7294381d 100644 --- a/packages/taro-service/src/utils/index.ts +++ b/packages/taro-service/src/utils/index.ts @@ -2,15 +2,13 @@ import * as path from 'path' import { merge } from 'lodash' import * as resolve from 'resolve' -import { getModuleDefaultExport } from '@tarojs/helper' +import { getModuleDefaultExport, NODE_MODULES_REG, isNpmPkg } from '@tarojs/helper' import { PluginItem } from '@tarojs/taro/types/compile' import { PluginType } from './constants' import { IPlugin } from './types' -export const isNpmPkg: (name: string) => boolean = name => !(/^(\.|\/)/.test(name)) - export function getPluginPath (pluginPath: string) { if (isNpmPkg(pluginPath) || path.isAbsolute(pluginPath)) return pluginPath throw new Error('plugin 和 preset 配置必须为绝对路径或者包名') @@ -45,13 +43,22 @@ export function mergePlugins (dist: PluginItem[], src: PluginItem[]) { // getModuleDefaultExport export function resolvePresetsOrPlugins (root: string, args, type: PluginType): IPlugin[] { return Object.keys(args).map(item => { + let pkgInfo const fPath = resolve.sync(item, { basedir: root, - extensions: ['.js', '.ts'] + extensions: ['.js', '.ts'], + packageFilter (pkg) { + pkgInfo = pkg + } }) + let name = fPath + if (NODE_MODULES_REG.test(fPath) && isNpmPkg(item)) { + name = pkgInfo.name || fPath + } return { id: fPath, path: fPath, + name, type, opts: args[item] || {}, apply () { diff --git a/packages/taro-service/src/utils/types.ts b/packages/taro-service/src/utils/types.ts index 899ffd858ecd..4217b6af0a7e 100644 --- a/packages/taro-service/src/utils/types.ts +++ b/packages/taro-service/src/utils/types.ts @@ -25,6 +25,7 @@ export interface IPaths { export interface IPlugin { id: string + name: string path: string opts: any type: PluginType From 8af00dd6feb2e5a369b4027d69c675a99011be3d Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 3 Jun 2020 17:26:17 +0800 Subject: [PATCH 11/15] =?UTF-8?q?feat(cli):=20build=20=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=A1=8C=E6=97=B6=E5=AF=B9=20plugin?= =?UTF-8?q?=20=E7=9A=84=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-cli/src/presets/commands/build.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/packages/taro-cli/src/presets/commands/build.ts b/packages/taro-cli/src/presets/commands/build.ts index 630c5793ad92..e4febd7b833f 100644 --- a/packages/taro-cli/src/presets/commands/build.ts +++ b/packages/taro-cli/src/presets/commands/build.ts @@ -29,6 +29,7 @@ export default (ctx) => { configPath, projectConfig: ctx.initialConfig }) + await checkPlugin(ctx, isWatch) if (checkResult.lines.length) { const NOTE_VALID = chalk.yellow('[!] ') const NOTE_INVALID = chalk.red('[✗] ') @@ -127,3 +128,67 @@ async function checkConfig ({ projectConfig, configPath }) { }) return result } + +function findFilesWithExt (dirname, ext) { + const glob = require('glob') + const pattern = Array.isArray(ext) ? `${dirname}/**/*{${ext.join(',')}}` : `${dirname}/**/*${ext}` + const files = glob.sync(pattern) + return files +} + +const PLUGIN_SASS = '@tarojs/plugin-sass' +const PLUGIN_LESS = '@tarojs/plugin-less' +const PLUGIN_STYLUS = '@tarojs/plugin-stylus' +const PLUGIN_UGLIFY = '@tarojs/plugin-uglify' +const PLUGIN_TERSER = '@tarojs/plugin-terser' + +const PLUGINS_CONFIG_DOC = 'https://nervjs.github.io/taro/docs/config-detail#plugins' + +function hadAddPlugin (plugins, pluginName) { + let hadAdd = false + plugins.forEach(item => { + if (item.id === pluginName || item.name === pluginName) { + hadAdd = true + } + }) + return hadAdd +} + +async function checkPlugin (ctx, isWatch) { + const plugins = ctx.plugins + const sassFiles = findFilesWithExt(ctx.paths.sourcePath, ['.scss', '.sass']) + if (sassFiles.length && !hadAddPlugin(plugins, PLUGIN_SASS)) { + console.log() + console.log(ctx.helper.chalk.red(`当前项目使用了 sass,请安装插件 ${PLUGIN_SASS},并且在 plugins 中进行配置,否则将无法编译 sass 文件!`)) + console.log(ctx.helper.chalk.red(`参考文档:${PLUGINS_CONFIG_DOC}`)) + console.log() + process.exit(1) + } + + const lessFiles = findFilesWithExt(ctx.paths.sourcePath, '.less') + if (lessFiles.length && !hadAddPlugin(plugins, PLUGIN_LESS)) { + console.log() + console.log(ctx.helper.chalk.red(`当前项目使用了 sass,请安装插件 ${PLUGIN_LESS},并且在 plugins 中进行配置,否则将无法编译 less 文件!`)) + console.log(ctx.helper.chalk.red(`参考文档:${PLUGINS_CONFIG_DOC}`)) + console.log() + process.exit(1) + } + + const stylusFiles = findFilesWithExt(ctx.paths.sourcePath, '.styl') + if (stylusFiles.length && !hadAddPlugin(plugins, PLUGIN_STYLUS)) { + console.log() + console.log(ctx.helper.chalk.red(`当前项目使用了 sass,请安装插件 ${PLUGIN_STYLUS},并且在 plugins 中进行配置,否则将无法编译 stylus 文件!`)) + console.log(ctx.helper.chalk.red(`参考文档:${PLUGINS_CONFIG_DOC}`)) + console.log() + process.exit(1) + } + + if (!isWatch) { + if (!hadAddPlugin(plugins, PLUGIN_UGLIFY) && !hadAddPlugin(plugins, PLUGIN_TERSER)) { + console.log() + console.log(ctx.helper.chalk.yellow(`检测到当前项目没有安装压缩插件 ${PLUGIN_UGLIFY} 或 ${PLUGIN_TERSER},打包时将无法压缩 JS 代码,请安装插件(安装其一即可),并且在 plugins 中进行配置!`)) + console.log(ctx.helper.chalk.yellow(`参考文档:${PLUGINS_CONFIG_DOC}`)) + console.log() + } + } +} From 70159a6fac496f9006754b87e6ffad80c5cb2e67 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 4 Jun 2020 18:45:23 +0800 Subject: [PATCH 12/15] =?UTF-8?q?feat(mini-runner):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=89=B9=E5=AE=9A=E7=9A=84?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/src/webpack/chain.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index fb7bd1f56d14..fc7ead48a108 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -192,6 +192,7 @@ export const getModule = (appPath: string, { const compileInclude = compile.include || [] const styleExtRegs = [/\.css$/] + styleExtRegs.push(new RegExp(`${fileType.style}$`)) const rules = chain.module.rules.entries() if (rules) { Object.keys(rules).forEach(item => { From 1684e9e4e13d9979ef518c1488b7983959334a70 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Fri, 5 Jun 2020 10:51:59 +0800 Subject: [PATCH 13/15] =?UTF-8?q?chore:=20=E4=BF=AE=E5=A4=8D=20ts=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-rn-runner/src/webpack/chain.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/taro-rn-runner/src/webpack/chain.ts b/packages/taro-rn-runner/src/webpack/chain.ts index bbc91d34d1fc..f1548556c0a6 100644 --- a/packages/taro-rn-runner/src/webpack/chain.ts +++ b/packages/taro-rn-runner/src/webpack/chain.ts @@ -37,16 +37,6 @@ const globalObjectMap = { [BUILD_TYPES.RN]: 'global' } -const defaultUglifyJsOption = { - keep_fnames: true, - output: { - comments: false, - keep_quoted_props: true, - quote_keys: true, - beautify: false - }, - warnings: false -} const defaultCSSCompressOption = { mergeRules: false, mergeIdents: false, From fc345ef45f2783812eda0a532910525c0bc2fc0f Mon Sep 17 00:00:00 2001 From: luckyadam Date: Fri, 5 Jun 2020 11:31:07 +0800 Subject: [PATCH 14/15] =?UTF-8?q?chore:=20=E4=BF=AE=E5=A4=8D=20webpack-run?= =?UTF-8?q?ner=20=E6=B5=8B=E8=AF=95=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/__tests__/index-test.ts | 8 ++++---- packages/taro-webpack-runner/src/util/chain.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/taro-webpack-runner/src/__tests__/index-test.ts b/packages/taro-webpack-runner/src/__tests__/index-test.ts index 68cded77b55b..e8b2bf9d04f2 100644 --- a/packages/taro-webpack-runner/src/__tests__/index-test.ts +++ b/packages/taro-webpack-runner/src/__tests__/index-test.ts @@ -48,22 +48,22 @@ describe('Regs', () => { babel: {} }, chain) expect(rule.css).toMatchObject({ - test: /\.(css|s[ac]ss|less|styl)\b/, + test: /\.css$/, oneOf: expect.any(Array) }) expect(rule.postcss).toMatchObject({ - test: /\.(css|s[ac]ss|less|styl)\b/, + test: /\.css$/, use: expect.any(Array), exclude: expect.any(Array) }) expect(rule.taroStyle).toMatchObject({ - test: /\.(css|s[ac]ss|less|styl)\b/, + test: /\.css$/, enforce: 'post', use: expect.any(Array), include: expect.any(Array) }) expect(rule.customStyle).toMatchObject({ - test: /\.(css|s[ac]ss|less|styl)\b/, + test: /\.css$/, enforce: 'post', use: expect.any(Array), exclude: expect.any(Array) diff --git a/packages/taro-webpack-runner/src/util/chain.ts b/packages/taro-webpack-runner/src/util/chain.ts index dd15e94fd673..65aade230ad7 100644 --- a/packages/taro-webpack-runner/src/util/chain.ts +++ b/packages/taro-webpack-runner/src/util/chain.ts @@ -266,13 +266,15 @@ const getModule = (appPath: string, { }] const styleExtRegs = [/\.css$/] - const rules = chain.module.rules.entries() - if (rules) { - Object.keys(rules).forEach(item => { - if (/^addChainStyle/.test(item) && rules[item].get('test')) { - styleExtRegs.push(rules[item].get('test')) - } - }) + if (chain.module) { + const rules = chain.module.rules.entries() + if (rules) { + Object.keys(rules).forEach(item => { + if (/^addChainStyle/.test(item) && rules[item].get('test')) { + styleExtRegs.push(rules[item].get('test')) + } + }) + } } const styleReg = new RegExp(styleExtRegs.map(reg => new RegExp(reg).source).join('|')) From 45b8251d3350780e6da546f8d772b3eb5d64e6ff Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 10 Jun 2020 17:49:40 +0800 Subject: [PATCH 15/15] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/templates/default/config/index.js | 5 ++++- packages/taro-cli/templates/default/pkg | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/taro-cli/templates/default/config/index.js b/packages/taro-cli/templates/default/config/index.js index 6fc1741ac6e9..d634e2d6f0ec 100644 --- a/packages/taro-cli/templates/default/config/index.js +++ b/packages/taro-cli/templates/default/config/index.js @@ -28,7 +28,10 @@ const config = { }] ] }, - plugins: [], + plugins: [<% if (css !== 'none') {%> + '@tarojs/plugin-<%= css %>',<%}%> + '@tarojs/plugin-terser' + ], defineConstants: { }, mini: { diff --git a/packages/taro-cli/templates/default/pkg b/packages/taro-cli/templates/default/pkg index 2d73ff7cbbd0..a6d4d87db1d8 100644 --- a/packages/taro-cli/templates/default/pkg +++ b/packages/taro-cli/templates/default/pkg @@ -16,6 +16,7 @@ "build:h5": "taro build --type h5", "build:rn": "taro build --type rn", "build:qq": "taro build --type qq", + "build:jd": "taro build --type jd", "build:quickapp": "taro build --type quickapp", "dev:weapp": "npm run build:weapp -- --watch", "dev:swan": "npm run build:swan -- --watch", @@ -24,6 +25,7 @@ "dev:h5": "npm run build:h5 -- --watch", "dev:rn": "npm run build:rn -- --watch", "dev:qq": "npm run build:qq -- --watch", + "dev:jd": "npm run build:jd -- --watch", "dev:quickapp": "npm run build:quickapp -- --watch" }, "author": "", @@ -50,6 +52,8 @@ "@types/react": "^16.4.6", "@types/webpack-env": "^1.13.6", "@tarojs/mini-runner": "<%= version %>", + "@tarojs/plugin-<%= css %>": "<%= version %>",<%}%> + "@tarojs/plugin-terser": "<%= version %>", "@tarojs/webpack-runner": "<%= version %>", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-decorators-legacy": "^1.3.4",