-
Notifications
You must be signed in to change notification settings - Fork 889
Expand file tree
/
Copy pathwebpack.config.js
More file actions
107 lines (95 loc) · 3.08 KB
/
webpack.config.js
File metadata and controls
107 lines (95 loc) · 3.08 KB
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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
class MyPlugin {
apply(compiler) {
compiler.hooks.emit.tap('MyPlugin', (compilation) => {
// Get the bundled file name
const fileName = Object.keys(compilation.assets)[0];
// Get the bundled file content
const fileContent = compilation.assets[fileName].source();
const header = `if (! jSuites && typeof(require) === 'function') {
var jSuites = require('jsuites');
}
if (! formula && typeof(require) === 'function') {
var formula = require('@jspreadsheet/formula');
}
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.jspreadsheet = factory();
}(this, (function () {`;
const footer = ` return jspreadsheet;
})));`;
// Updated file content with custom content added
const updatedFileContent = header + '\n\n' + fileContent + '\n\n' + footer;
// Replace the bundled file content with updated content
compilation.assets[fileName] = {
source: () => updatedFileContent,
size: () => updatedFileContent.length,
};
});
}
}
let isProduction = process.env.NODE_ENV === 'production';
const webpack = {
target: ['web', 'es5'],
entry: isProduction ? './src/index' : './src/test.js',
mode: isProduction ? 'production' : 'development',
externals: {},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
library: 'jspreadsheet',
libraryExport: 'default',
},
optimization: {
minimize: true,
},
devServer: {
static: {
directory: path.join(__dirname, '/public'),
},
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
port: 8000,
devMiddleware: {
publicPath: 'https://localhost:3000/',
},
hot: 'only',
},
plugins: [],
module: {
rules: [
isProduction
? {
test: /\.js$/,
use: [
{
loader: path.resolve('build.cjs'),
options: {},
},
],
}
: null,
{
test: /\.css$/,
use: [isProduction ? MiniCssExtractPlugin.loader : 'style-loader', 'css-loader'],
},
],
},
stats: {
warnings: false,
},
};
if (isProduction) {
webpack.plugins.push(new MyPlugin());
webpack.plugins.push(
new MiniCssExtractPlugin({
filename: 'jspreadsheet.css',
})
);
}
module.exports = webpack;