UNPKG

@omni-door/tpl-spa-vue

Version:
21 lines (20 loc) 5.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.tpl_webpack_prod = void 0; var utils_1 = require("@omni-door/utils"); var rules_style_css_1 = __importDefault(require("./rules_style_css")); var rules_style_less_1 = __importDefault(require("./rules_style_less")); var rules_style_scss_1 = __importDefault(require("./rules_style_scss")); var rules_style_all_1 = __importDefault(require("./rules_style_all")); var tpl = "`${use_strict}\n\nconst path = require('path');\nconst webpack = require('webpack');\nconst { merge } = require('webpack-merge');\nconst TerserPlugin = require('terser-webpack-plugin');\nconst HtmlWebpackPlugin = require('html-webpack-plugin');\nconst HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin');${style ? `\nconst CssMinimizerPlugin = require('css-minimizer-webpack-plugin');\nconst MiniCssExtractPlugin = require('mini-css-extract-plugin');\nconst HTMLInlineCSSWebpackPlugin = require(\"html-inline-css-webpack-plugin\").default;` : ''}\nconst { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');\n\nconst commonConfig = require(path.resolve(__dirname, 'webpack.config.common.js'));\nconst { build } = require(path.resolve(__dirname, '${configFileName}'));\nconst {\n srcDir = path.resolve(__dirname, '../src/'),\n outDir = path.resolve(__dirname, '../lib/'),\n hash\n} = build || {};\nconst publicPath = '';\n\nmodule.exports = merge(commonConfig, {\n // Uncomment to enable source maps.\n // devtool: 'cheap-module-source-map',\n cache: {\n type: 'memory'\n },\n output: {\n publicPath\n },\n module: {\n rules: [\n ${alter_style({\n css: 'rules_style_css',\n less: 'rules_style_less',\n scss: 'rules_style_scss',\n all: 'rules_style_all',\n })}\n ]\n },\n optimization: {\n minimize: true,\n minimizer: [\n new TerserPlugin({\n parallel: true,\n terserOptions: {\n output: {\n comments: false\n }\n }\n })${style ? `,\n new CssMinimizerPlugin({\n minimizerOptions: {\n preset: [\n \"default\",\n {\n discardComments: { removeAll: true },\n },\n ],\n }\n })` : ''}\n ],\n chunkIds: 'named',\n splitChunks: {\n chunks: 'all',\n cacheGroups: {\n polyfill: {\n chunks: 'all',\n test: /(core-js|regenerator-runtime)/,\n enforce: true,\n name: 'polyfill',\n priority: 110\n },\n flexible: {\n chunks: 'all',\n test: /amfe-flexible/,\n enforce: true,\n name: 'flexible',\n priority: 105\n },\n vendors: {\n chunks: 'all',\n test: /(vue|vue-router|vuex|mobx|mobx-vue)/,\n enforce: true,\n name: 'vendors',\n priority: 100,\n reuseExistingChunk: true\n },\n commons: {\n chunks: 'all',\n test: /(axios)/,\n enforce: true,\n name: 'chunk',\n priority: 90,\n reuseExistingChunk: true\n },\n asyncs: {\n chunks: 'async',\n enforce: true,\n name: 'chunk.async',\n priority: 80,\n reuseExistingChunk: true\n }\n }\n }\n },\n plugins: [\n new webpack.DefinePlugin({\n __VUE_OPTIONS_API__: JSON.stringify(true),\n __VUE_PROD_DEVTOOLS__: JSON.stringify(false)\n }),\n ${style ? `\n new MiniCssExtractPlugin({\n filename: hash ? \\`[name].[\\${typeof hash === 'string' ? hash : 'contenthash'}:8].css\\` : '[name].css'\n }),\n ` : ''}\n // Uncomment to analyze bundle output.\n // new BundleAnalyzerPlugin({\n // analyzerMode: 'static',\n // defaultSizes: 'parsed',\n // reportFilename: './bundle_analysis.html'\n // }),\n\n new HtmlWebpackPlugin({\n path: path.resolve(outDir),\n template: path.resolve(srcDir, 'index.html'),\n minify:{\n removeComments: true,\n collapseWhitespace: true\n },\n // filename: hash ? 'index.[hash:8].html' : 'index.html',\n // hash: !!hash,\n filename: 'index.html'\n }),\n\n // Serve static assets from a shared CDN.\n // This can reduce asset load time and build time.\n // new HtmlWebpackExternalsPlugin({\n // externals: [\n // {\n // module: 'vue',\n // entry: 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.7/vue.cjs.prod.min.js',\n // global: 'Vue'\n // }\n // {\n // module: 'vue-router',\n // entry: 'https://cdnjs.cloudflare.com/ajax/libs/vue-router/4.0.4/vue-router.cjs.prod.min.js',\n // global: 'VueRouter'\n // }\n // ]\n // })${style ? `,\n // Inline synchronous external CSS links into the HTML.\n //! Can reduce time to first paint.\n new HTMLInlineCSSWebpackPlugin({\n filter(fileName) {\n //! If you change the splitChunks async configuration,\n //! filter out async CSS files to avoid a blank page.\n return !fileName.includes('async');\n }\n })\n ` : ''}\n ],\n mode: 'production'\n});\n`"; exports.tpl_webpack_prod = { tpl: tpl, rules_style_css: rules_style_css_1.default, rules_style_less: rules_style_less_1.default, rules_style_scss: rules_style_scss_1.default, rules_style_all: rules_style_all_1.default }; exports.default = utils_1.tplEngineInit(exports.tpl_webpack_prod, 'tpl');