-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
145 lines (132 loc) · 3.85 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireDefault(require("fs"));
var _webpackVendorReplace = _interopRequireDefault(require("./webpack.vendorReplace.plugin"));
var _index = _interopRequireDefault(require("./index"));
var _miniCssExtractPlugin = _interopRequireDefault(require("mini-css-extract-plugin"));
var manifest = JSON.parse(_fs.default.readFileSync(_path.default.join(process.cwd(), 'manifest.json')));
var type = Object.keys(manifest)[0];
var tag = Object.keys(manifest[type])[0];
var vendors = (0, _index.default)();
var _default = Object.assign({}, {
devtool: 'eval',
mode: 'development',
entry: {
element: process.cwd() + '/' + tag + '/index.js'
},
output: {
path: _path.default.resolve(process.cwd(), 'public/dist/'),
// Assets dist path
publicPath: 'auto',
// Used to generate URL's
filename: '[name].bundle.js',
// Main bundle file
chunkFilename: '[name].bundle.js',
chunkLoadingGlobal: 'vcvWebpackJsonp4x',
assetModuleFilename: 'assets/[hash][ext][query]'
},
optimization: {
minimize: false,
runtimeChunk: 'single',
chunkIds: 'named',
moduleIds: 'named',
splitChunks: {
cacheGroups: {
default: false,
vendor: {
chunks: 'initial',
name: 'vendor',
// test: /[\\/]node_modules[\\/]/,
test: function test(module) {
var found = false;
if (module.resource && module.resource.indexOf('node_modules') !== -1) {
vendors.forEach(function (vendor) {
if (module.resource && module.resource.indexOf(vendor) !== -1) {
if (vendor === 'react') {
// check for only react not the other packages
if (module.resource.indexOf('node_modules/react/') !== -1) {
found = true;
}
} else {
found = true;
}
}
});
}
return found;
},
enforce: true
},
element: {
chunks: 'initial',
name: 'element',
test: 'element',
enforce: true
}
}
}
},
plugins: [new _miniCssExtractPlugin.default({
filename: '[name].bundle.css'
}), new _webpackVendorReplace.default(tag + '/index.js', type)],
module: {
rules: [{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
}, {
test: /\.js$/,
use: {
loader: 'babel-loader'
},
exclude: /node_modules/
}, {
test: /\.css|\.less$/,
exclude: [/styles\.css/, /editor\.css/],
use: [{
loader: _miniCssExtractPlugin.default.loader
}, 'css-loader', {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: function plugins() {
return [require('autoprefixer')()];
}
}
}
}, {
loader: 'less-loader',
options: {
lessOptions: {
math: 'always'
}
}
}]
}, {
test: /\.(png|jpe?g|gif|svg|ttf|woff)$/,
type: 'asset/resource'
}, {
test: /\.raw(\?v=\d+\.\d+\.\d+)?$/,
use: 'raw-loader'
}]
},
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
os: require.resolve('os-browserify/browser'),
util: require.resolve('util/'),
buffer: require.resolve('buffer/'),
fs: require.resolve('./lib/slim-fs.js'),
http: false,
https: false,
stream: false
}
}
});
exports.default = _default;