UNPKG

6.37 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.tpl_webpack_prod = void 0;
7var utils_1 = require("@omni-door/utils");
8var rules_style_css_1 = __importDefault(require("./rules_style_css"));
9var rules_style_less_1 = __importDefault(require("./rules_style_less"));
10var rules_style_scss_1 = __importDefault(require("./rules_style_scss"));
11var rules_style_all_1 = __importDefault(require("./rules_style_all"));
12var 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 OptimizeCSSAssetsPlugin = require('optimize-css-assets-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 // \u9700\u8981 source-map \u8BF7\u5F00\u542F\n // Remove annotation when need source-map\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 OptimizeCSSAssetsPlugin({\n cssProcessor: require('cssnano'),\n cssProcessorOptions: {\n reduceIndents: false,\n autoprefixer: false\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 },\n commons: {\n chunks: 'all',\n test: /(axios)/,\n enforce: true,\n name: 'chunk',\n priority: 90\n },\n asyncs: {\n chunks: 'async',\n enforce: true,\n name: 'chunk.async',\n priority: 80\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 // ! \u9700\u8981\u5206\u6790\u6253\u5305\u65F6\uFF0C\u8BF7\u6253\u5F00\u6CE8\u91CA\n // Remove annotation when need analyze package\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 // \u8D70\u7EDF\u4E00 CDN \u7684\u9759\u6001\u8D44\u6E90\n // The static resources of CDN\n // \u80FD\u4E00\u5B9A\u7A0B\u5EA6\u4E0A\u51CF\u5C11\u8D44\u6E90\u52A0\u8F7D\u65F6\u957F\u548C\u6784\u5EFA\u65F6\u957F\n // It can reduce some download source and construction 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 // \u5C06\u540C\u6B65\u7684\u5916\u94FE link \u6CE8\u5165\u5230 html \u4E2D\n // Inject the outer-links into html-style tag\n //! \u80FD\u4E00\u5B9A\u7A0B\u5EA6\u4E0A\u51CF\u5C11\u9996\u5C4F\u65F6\u957F\n // It can reduce some first-screen time\n new HTMLInlineCSSWebpackPlugin({\n filter(fileName) {\n //! \u6CE8\u610F\uFF0C\u82E5\u662F\u66F4\u6539\u4E86 splitChunks\u5F02\u6B65\u52A0\u8F7D \u7684\u914D\u7F6E\n // Note that if you change the configuration of splitChunks\n //! \u9700\u8981\u8FC7\u6EE4\u6389\u5F02\u6B65\u7684css\u6587\u4EF6\uFF0C\u5426\u5219\u4F1A\u5BFC\u81F4\u9875\u9762\u767D\u5C4F\uFF01\uFF01\uFF01\n // You need to filter out asynchronous CSS files, otherwise the page will be white!!!\n return !fileName.includes('async');\n }\n })\n ` : ''}\n ],\n mode: 'production'\n});\n`";
13exports.tpl_webpack_prod = {
14 tpl: tpl,
15 rules_style_css: rules_style_css_1.default,
16 rules_style_less: rules_style_less_1.default,
17 rules_style_scss: rules_style_scss_1.default,
18 rules_style_all: rules_style_all_1.default
19};
20exports.default = utils_1.tplEngineInit(exports.tpl_webpack_prod, 'tpl');