|
1 | | -const path = require("path"); |
2 | | -const TerserPlugin = require("terser-webpack-plugin"); |
3 | | -const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
4 | | -const { CleanWebpackPlugin } = require("clean-webpack-plugin"); |
5 | | - |
6 | | -module.exports = (env, argv) => { |
7 | | - let isProduction = false; |
8 | | - if (argv.mode === "production") isProduction = true; |
9 | | - |
10 | | - const config = { |
11 | | - entry: { |
12 | | - "CoCreate-utils": "./src/index.js" |
13 | | - }, |
14 | | - output: { |
15 | | - path: path.resolve(__dirname, "dist"), |
16 | | - filename: isProduction ? "[name].min.js" : "[name].js", |
17 | | - libraryTarget: "umd", |
18 | | - libraryExport: "default", |
19 | | - library: ["CoCreate", "utils"], |
20 | | - globalObject: "this" |
21 | | - }, |
22 | | - |
23 | | - plugins: [ |
24 | | - new CleanWebpackPlugin(), |
25 | | - new MiniCssExtractPlugin({ |
26 | | - filename: "[name].css" |
27 | | - }) |
28 | | - ], |
29 | | - // Default mode for Webpack is production. |
30 | | - // Depending on mode Webpack will apply different things |
31 | | - // on final bundle. For now we don't need production's JavaScript |
32 | | - // minifying and other thing so let's set mode to development |
33 | | - mode: isProduction ? "production" : "development", |
34 | | - module: { |
35 | | - rules: [ |
36 | | - { |
37 | | - test: /.js$/, |
38 | | - exclude: /(node_modules)/, |
39 | | - use: { |
40 | | - loader: "babel-loader", |
41 | | - options: { |
42 | | - plugins: [ |
43 | | - "@babel/plugin-transform-modules-commonjs" |
44 | | - ] |
45 | | - } |
46 | | - } |
47 | | - }, |
48 | | - { |
49 | | - test: /.css$/i, |
50 | | - use: [ |
51 | | - { |
52 | | - loader: "style-loader", |
53 | | - options: { injectType: "linkTag" } |
54 | | - }, |
55 | | - "file-loader" |
56 | | - ] |
57 | | - } |
58 | | - ] |
59 | | - }, |
60 | | - |
61 | | - // add source map |
62 | | - ...(isProduction ? {} : { devtool: "eval-source-map" }), |
63 | | - |
64 | | - optimization: { |
65 | | - minimize: true, |
66 | | - minimizer: [ |
67 | | - new TerserPlugin({ |
68 | | - extractComments: true, |
69 | | - // cache: true, |
70 | | - parallel: true, |
71 | | - // sourceMap: true, // Must be set to true if using source-maps in production |
72 | | - terserOptions: { |
73 | | - // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions |
74 | | - // extractComments: 'all', |
75 | | - compress: { |
76 | | - drop_console: true |
77 | | - } |
78 | | - } |
79 | | - }) |
80 | | - ], |
81 | | - splitChunks: { |
82 | | - chunks: "all", |
83 | | - minSize: 200, |
84 | | - // maxSize: 99999, |
85 | | - //minChunks: 1, |
86 | | - |
87 | | - cacheGroups: { |
88 | | - defaultVendors: false |
89 | | - } |
90 | | - } |
91 | | - } |
92 | | - }; |
93 | | - return config; |
94 | | -}; |
| 1 | +const path = require("path"); |
| 2 | +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
| 3 | +const { EsbuildPlugin } = require("esbuild-loader"); |
| 4 | +const { FileUploader } = require("@cocreate/webpack"); |
| 5 | + |
| 6 | +module.exports = async (env, argv) => { |
| 7 | + const isProduction = argv && argv.mode === "production"; |
| 8 | + const config = { |
| 9 | + entry: { |
| 10 | + "CoCreate-utils": "./src/index.js" |
| 11 | + }, |
| 12 | + output: { |
| 13 | + path: path.resolve(__dirname, "dist"), |
| 14 | + filename: isProduction ? "[name].min.js" : "[name].js", |
| 15 | + libraryExport: "default", |
| 16 | + library: ["CoCreate", "utils"], |
| 17 | + clean: true |
| 18 | + }, |
| 19 | + plugins: [ |
| 20 | + new MiniCssExtractPlugin({ |
| 21 | + filename: isProduction ? "[name].min.css" : "[name].css" |
| 22 | + }), |
| 23 | + new FileUploader(env, argv) |
| 24 | + ], |
| 25 | + mode: isProduction ? "production" : "development", |
| 26 | + devtool: isProduction ? "source-map" : "eval-source-map", |
| 27 | + module: { |
| 28 | + rules: [ |
| 29 | + { |
| 30 | + test: /.js$/, |
| 31 | + exclude: /node_modules/, |
| 32 | + use: { |
| 33 | + loader: "esbuild-loader", |
| 34 | + options: { |
| 35 | + loader: "js", |
| 36 | + target: "es2017" |
| 37 | + } |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + test: /.css$/i, |
| 42 | + use: [MiniCssExtractPlugin.loader, "css-loader"] |
| 43 | + } |
| 44 | + ] |
| 45 | + }, |
| 46 | + optimization: { |
| 47 | + minimize: isProduction, |
| 48 | + minimizer: [ |
| 49 | + new EsbuildPlugin({ |
| 50 | + target: "es2017", |
| 51 | + css: true |
| 52 | + }) |
| 53 | + ], |
| 54 | + splitChunks: { |
| 55 | + cacheGroups: { |
| 56 | + defaultVendors: false |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + performance: { |
| 61 | + hints: isProduction ? "warning" : false |
| 62 | + } |
| 63 | + }; |
| 64 | + return config; |
| 65 | +}; |
0 commit comments