4 Star 2 Fork 0

mirrors_jspreadsheet/ce

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
webpack.config.cjs 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
Paul 提交于 2024-03-29 13:08 . 4.2.1 precedence of jSuites fix
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');
}
;(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';
let dependencies = {};
if (isProduction) {
dependencies = {
jsuites: "''",
}
}
const webpack = {
target: ['web', 'es5'],
entry: isProduction ? './src/index' : './src/test.js',
mode: isProduction ? 'production' : 'development',
externals: dependencies,
output: {
filename: 'index.js',
library: 'jspreadsheet'
},
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: 3007,
devMiddleware: {
publicPath: "https://localhost:3000/",
},
hot: "only",
},
plugins: [],
module: {
rules: [
{
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;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_jspreadsheet/ce.git
git@gitee.com:mirrors_jspreadsheet/ce.git
mirrors_jspreadsheet
ce
ce
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385