1 | 'use strict';
|
2 | const fs = require('fs');
|
3 | const path = require('path');
|
4 | const webpack = require('webpack');
|
5 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
6 | const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
|
7 | const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
8 | const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin")
|
9 |
|
10 |
|
11 | const getClientEnvironment = require('./env');
|
12 | const paths = require('./paths');
|
13 |
|
14 | const env = getClientEnvironment();
|
15 | const appPackageJson = require(paths.appPackageJson);
|
16 | const appDirectory = fs.realpathSync(process.cwd());
|
17 | module.exports = {
|
18 | mode: 'production',
|
19 | optimization: {
|
20 | minimizer: [
|
21 | new UglifyJsPlugin({
|
22 | cache: true,
|
23 | parallel: true,
|
24 | sourceMap: false
|
25 | }),
|
26 | new OptimizeCSSAssetsPlugin({})
|
27 | ]
|
28 | },
|
29 | entry: [
|
30 | paths.appIndexJs
|
31 | ],
|
32 | output: {
|
33 | filename: appPackageJson.name + '.min.js',
|
34 | path: path.join(appDirectory, "/build/prod/"),
|
35 | library: "MKApp_" + appPackageJson.name.replace(/-/g, '_'),
|
36 | libraryTarget: "umd"
|
37 | },
|
38 | resolve: {
|
39 | extensions: [".js"]
|
40 | },
|
41 | externals: {
|
42 | "react": {
|
43 | root: 'React',
|
44 | commonjs2: 'react',
|
45 | commonjs: 'react',
|
46 | amd: 'react'
|
47 | },
|
48 | "react-dom": {
|
49 | root: 'ReactDOM',
|
50 | commonjs2: 'react-dom',
|
51 | commonjs: 'react-dom',
|
52 | amd: 'react-dom'
|
53 | },
|
54 | "immutable": {
|
55 | root: 'Immutable',
|
56 | commonjs2: 'immutable',
|
57 | commonjs: 'immutable',
|
58 | amd: 'immutable'
|
59 | },
|
60 | "moment": "moment",
|
61 | "mk-sdk": "MK",
|
62 | "mk-app-loader": {
|
63 | root: ["MK", "appLoader"],
|
64 | commonjs: "MK.appLoader",
|
65 | commonjs2: "MK.appLoader",
|
66 | amd: "MK.appLoader"
|
67 | },
|
68 | "mk-utils": {
|
69 | root: ["MK", "utils"],
|
70 | commonjs2: "MK.utils",
|
71 | amd: "MK.utils",
|
72 | commonjs: "MK.utils",
|
73 | },
|
74 | "mk-component": {
|
75 | root: ["MK", "component"],
|
76 | commonjs2: "MK.component",
|
77 | amd: "MK.component",
|
78 | commonjs: "MK.component"
|
79 | },
|
80 | "mk-meta-engine": {
|
81 | commonjs: ["MK", "metaEngine"],
|
82 | commonjs2: "MK.metaEngine",
|
83 | amd: "MK.metaEngine",
|
84 | root: "MK.metaEngine"
|
85 | },
|
86 | "mk-aar-form": "mk-aar-form",
|
87 | "mk-aar-grid": "mk-aar-grid",
|
88 | "echarts": "echarts"
|
89 | },
|
90 | module: {
|
91 | rules: [{
|
92 | test: /\.(js|jsx|mjs)$/,
|
93 | include: paths.appSrc,
|
94 | exclude: paths.appNodeModules,
|
95 | loader: require.resolve('babel-loader'),
|
96 | options: {
|
97 | babelrc: false,
|
98 | presets: [
|
99 | 'env',
|
100 | 'stage-2',
|
101 | 'react',
|
102 | ],
|
103 | plugins: [
|
104 | ["transform-runtime", {
|
105 | "helpers": false,
|
106 | "polyfill": false,
|
107 | "regenerator": true,
|
108 | "moduleName": "babel-runtime"
|
109 | }],
|
110 | 'add-module-exports',
|
111 | 'transform-decorators-legacy'
|
112 | ],
|
113 | compact: true,
|
114 | },
|
115 | }, {
|
116 | test: /\.css$/,
|
117 | use: [MiniCssExtractPlugin.loader, 'css-loader']
|
118 | }, {
|
119 | test: /\.less$/,
|
120 | use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
|
121 |
|
122 | }, {
|
123 | test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
|
124 | use: {
|
125 | loader: 'file-loader',
|
126 | options: {
|
127 | name: '[name].[ext]',
|
128 | limit: 8192
|
129 | }
|
130 | }
|
131 | }],
|
132 | },
|
133 | plugins: [
|
134 | new webpack.DefinePlugin(env.stringified),
|
135 |
|
136 | new CaseSensitivePathsPlugin(),
|
137 | new MiniCssExtractPlugin({ filename: appPackageJson.name + '.min.css' })
|
138 | ],
|
139 | node: {
|
140 | dgram: 'empty',
|
141 | fs: 'empty',
|
142 | net: 'empty',
|
143 | tls: 'empty',
|
144 | child_process: 'empty',
|
145 | }
|
146 | };
|