UNPKG

@mypaas/hcm-cli

Version:

Vant Cli 是一个 Vue 组件库构建工具,通过 Vant Cli 可以快速搭建一套功能完备的 Vue 组件库。

137 lines (136 loc) 4.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.baseConfig = exports.genBaseConfig = void 0; const sass_1 = __importDefault(require("sass")); const friendly_errors_webpack_plugin_1 = __importDefault(require("@nuxt/friendly-errors-webpack-plugin")); const vue_loader_1 = require("vue-loader"); const path_1 = require("path"); const fs_1 = require("fs"); const logger_1 = require("../common/logger"); const constant_1 = require("../common/constant"); const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin")); const REPLACE_LOADER = { loader: path_1.resolve(__dirname, '../compiler/prefix-replace-loader.js'), }; const CACHE_LOADER = { loader: 'cache-loader', options: { cacheDirectory: constant_1.CACHE_DIR, }, }; const getCssLoaders = (extractCss = false) => { const CSS_LOADERS = [ extractCss ? mini_css_extract_plugin_1.default.loader : 'style-loader', 'css-loader', { loader: 'postcss-loader', options: { config: { path: constant_1.POSTCSS_CONFIG_FILE, }, }, }, REPLACE_LOADER, ]; return CSS_LOADERS; }; const getPlugins = (extractCss = false) => { const plugins = [ new vue_loader_1.VueLoaderPlugin(), new friendly_errors_webpack_plugin_1.default({ clearConsole: false, logLevel: 'WARNING', }), ]; if (extractCss) { plugins.push(new mini_css_extract_plugin_1.default({ filename: '[name].css' })); } const tsconfigPath = path_1.join(constant_1.CWD, 'tsconfig.json'); if (fs_1.existsSync(tsconfigPath)) { const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin'); plugins.push(new ForkTsCheckerPlugin({ formatter: 'codeframe', vue: { enabled: true }, logger: { // skip info message info() { }, warn(message) { logger_1.consola.warn(message); }, error(message) { logger_1.consola.error(message); }, }, })); } return plugins; }; const VUE_LOADER = { loader: 'vue-loader', options: { compilerOptions: { preserveWhitespace: false, }, }, }; function genBaseConfig({ extractCss, } = {}) { const cssLoaders = getCssLoaders(extractCss); const plugins = getPlugins(extractCss); return { mode: 'development', resolve: { extensions: [...constant_1.SCRIPT_EXTS, ...constant_1.STYLE_EXTS], }, module: { rules: [ { test: /\.vue$/, use: [CACHE_LOADER, VUE_LOADER, REPLACE_LOADER], }, { test: /\.(js|ts|jsx|tsx)$/, exclude: /node_modules\/(?!(@mypaas\/hcm-cli))/, use: [CACHE_LOADER, 'babel-loader', REPLACE_LOADER], }, { test: /\.css$/, sideEffects: true, use: cssLoaders, }, { test: /\.less$/, sideEffects: true, use: [...cssLoaders, 'less-loader'], }, { test: /\.scss$/, sideEffects: true, use: [ ...cssLoaders, { loader: 'sass-loader', options: { implementation: sass_1.default, }, }, ], }, { test: /\.md$/, use: [ CACHE_LOADER, VUE_LOADER, '@vant/markdown-loader', REPLACE_LOADER, ], }, ], }, plugins, }; } exports.genBaseConfig = genBaseConfig; exports.baseConfig = genBaseConfig();