|
1 |
| -const path = require("path") |
2 |
| - |
3 |
| -const { CleanWebpackPlugin } = require("clean-webpack-plugin") |
4 |
| -const TerserPlugin = require("terser-webpack-plugin") |
5 |
| -const MiniCssExtractPlugin = require("mini-css-extract-plugin") |
6 |
| -const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); |
7 |
| - |
8 |
| -let isProduction = process.env.NODE_ENV === "production" |
9 |
| - |
10 |
| -module.exports = { |
11 |
| - entry: { |
12 |
| - CoCreateCSS: "./src/index.js", |
13 |
| - }, |
14 |
| - output: { |
15 |
| - path: path.resolve(__dirname, "dist"), |
16 |
| - filename: isProduction ? "[name].min.js" : "[name].js", |
17 |
| - chunkFilename: isProduction ? '[name].min.js' : '[name].js', |
18 |
| - libraryTarget: "umd", |
19 |
| - libraryExport: "default", |
20 |
| - library: ["CoCreate", "css"], |
21 |
| - globalObject: "this", |
22 |
| - ...(isProduction ? { /*publicPath: 'https://cdn.cocreate.app/',*/ } : {}), |
23 |
| - }, |
24 |
| - |
25 |
| - plugins: [ |
26 |
| - new CleanWebpackPlugin(), |
27 |
| - new MiniCssExtractPlugin({ |
28 |
| - filename: isProduction ? 'CoCreate.min.css' : 'CoCreate.css', |
29 |
| - }), |
30 |
| - ], |
31 |
| - |
32 |
| - mode: isProduction ? "production" : "development", |
33 |
| - module: { |
34 |
| - rules: [ |
35 |
| - { |
36 |
| - test: /.js$/, |
37 |
| - exclude: /(node_modules)/, |
38 |
| - use: { |
39 |
| - loader: "babel-loader", |
40 |
| - options: { |
41 |
| - plugins: ["@babel/plugin-transform-modules-commonjs"], |
42 |
| - }, |
43 |
| - }, |
44 |
| - }, |
45 |
| - { |
46 |
| - test: /.css$/i, |
47 |
| - use: [ |
48 |
| - MiniCssExtractPlugin.loader, |
49 |
| - 'css-loader' |
50 |
| - ] |
51 |
| - }, |
52 |
| - ], |
53 |
| - }, |
54 |
| - |
55 |
| - // add source map |
56 |
| - ...(isProduction ? {} : { devtool: "eval-source-map" }), |
57 |
| - |
58 |
| - optimization: { |
59 |
| - minimize: true, |
60 |
| - minimizer: [ |
61 |
| - new CssMinimizerPlugin(), |
62 |
| - new TerserPlugin({ |
63 |
| - extractComments: true, |
64 |
| - // cache: true, |
65 |
| - parallel: true, |
66 |
| - // sourceMap: true, // Must be set to true if using source-maps in production |
67 |
| - terserOptions: { |
68 |
| - compress: { |
69 |
| - drop_console: true, |
70 |
| - }, |
71 |
| - }, |
72 |
| - }), |
73 |
| - ] |
74 |
| - }, |
75 |
| -} |
| 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 | + CoCreateCSS: "./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", "coCreateCSS"], |
| 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