From 82468146ebf4ca2dfae936c9f328908ac95622c0 Mon Sep 17 00:00:00 2001 From: fay Date: Tue, 4 Aug 2020 17:52:06 +0800 Subject: [PATCH] =?UTF-8?q?QFX-1451=20feat:=20=E5=BC=80=E6=94=BEless?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpack/webpack.common.js | 81 ++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index d3cac877d1..14edf56148 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,10 +1,23 @@ -const MiniCssExtractPlugin = require("mini-css-extract-plugin"); -const autoprefixer = require("autoprefixer"); -const path = require("path"); +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const autoprefixer = require('autoprefixer'); +const path = require('path'); +const fs = require('fs'); -const dirs = require("./dirs"); +const dirs = require('./dirs'); -const attachments = require("./attachments"); +const attachments = require('./attachments'); + +let lessVariables = {}; + +if (process.env.LESS_CONFIG_PATH) { + const lessConfigPath = path.isAbsolute(process.env.LESS_CONFIG_PATH) + ? process.env.LESS_CONFIG_PATH + : path.resolve(__dirname, '../', process.env.LESS_CONFIG_PATH); + + lessVariables = fs.existsSync(lessConfigPath) + ? require(lessConfigPath) || {} + : {}; +} module.exports = { entry: { @@ -17,8 +30,8 @@ module.exports = { underscore: '_', }, resolve: { - mainFields: ["module", "main"], - extensions: [".js", ".ts"], + mainFields: ['module', 'main'], + extensions: ['.js', '.ts'], }, module: { rules: [ @@ -26,17 +39,20 @@ module.exports = { test: /\.(js|ts)$/, include: [dirs.NODE_MODULES, dirs.PRIVATE, dirs.TYPESCRIPT], exclude: /node_modules(\/|\\)core-js/, - use: [{ - loader: "babel-loader", - options: { - configFile: dirs.IE8_BABEL_CONFIG, + use: [ + { + loader: 'babel-loader', + options: { + configFile: dirs.IE8_BABEL_CONFIG, + }, }, - }, { - loader: "source-map-loader", - options: { - enforce: "pre", + { + loader: 'source-map-loader', + options: { + enforce: 'pre', + }, }, - }], + ], }, { test: /\.js$/, @@ -51,9 +67,9 @@ module.exports = { ], use: [ { - loader: "source-map-loader", + loader: 'source-map-loader', options: { - enforce: "pre", + enforce: 'pre', }, }, ], @@ -63,44 +79,49 @@ module.exports = { include: [path.resolve(__dirname, '../', attachments.lodash)], use: [ { - loader: "script-loader", + loader: 'script-loader', }, ], }, { test: path.resolve(__dirname, '../', attachments.fix), - use: [{ - loader: 'expose-loader', - options: 'Fix', - }], + use: [ + { + loader: 'expose-loader', + options: 'Fix', + }, + ], }, { test: path.resolve(__dirname, '../', attachments.fixIE), - use: [{ - loader: 'expose-loader', - options: 'Fix', - }], + use: [ + { + loader: 'expose-loader', + options: 'Fix', + }, + ], }, { test: /\.(css|less)$/, use: [ MiniCssExtractPlugin.loader, { - loader: "css-loader", + loader: 'css-loader', options: { url: false, }, }, { - loader: "postcss-loader", + loader: 'postcss-loader', options: { plugins: [autoprefixer], }, }, { - loader: "less-loader", + loader: 'less-loader', options: { relativeUrls: false, + modifyVars: lessVariables, }, }, ],