1 Star 0 Fork 49

liuyf2020/spriteJS

forked from 奇虎360/spriteJS 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
webpack.config.js 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
akira-cn 提交于 2020-07-16 11:37 . update gl-renderer & add version info
const webpack = require('webpack');
const EsmWebpackPlugin = require('@purtuga/esm-webpack-plugin');
const path = require('path');
const fs = require('fs');
module.exports = function (env = {}) {
let babelConf;
const babelRC = env.esnext ? './.es6.babelrc' : './.babelrc';
if(fs.existsSync(babelRC)) {
babelConf = JSON.parse(fs.readFileSync(babelRC));
babelConf.babelrc = false;
}
const plugins = [];
if(env.mode === 'development') {
plugins.push(new webpack.HotModuleReplacementPlugin({
multiStep: true,
}));
}
if(env.module) {
plugins.push(new EsmWebpackPlugin());
}
plugins.push(new webpack.DefinePlugin({
__DEV__: env.mode === 'development',
}));
let filename = '[name]';
if(env.esnext) filename += '.es';
if(env.module) filename += 'm';
if(env.mode === 'production') filename += '.min';
filename += '.js';
const entry = {
spritejs: './src/index',
'spritejs.worker': './src/index.worker',
};
plugins.push(new webpack.DefinePlugin({
__SPRITEVER__: `"${require('./package.json').version}"`,
}));
return {
mode: env.mode || 'none',
entry,
output: {
path: path.resolve(__dirname, 'dist'),
filename,
publicPath: '/js/',
library: ['spritejs'],
libraryTarget: env.module ? 'var' : 'umd',
// libraryExport: 'default',
globalObject: 'this',
},
resolve: {
alias: {
'gl-renderer': 'gl-renderer/src',
'@mesh.js/core': '@mesh.js/core/src',
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!@mesh.js|gl-renderer).*/,
use: {
loader: 'babel-loader',
options: babelConf,
},
},
{
test: /\.(frag|vert|glsl)$/,
use: {
loader: 'raw-loader',
options: {},
},
},
],
/* Advanced module configuration (click to show) */
},
externals: {
},
// Don't follow/bundle these modules, but request them at runtime from the environment
stats: 'errors-only',
// lets you precisely control what bundle information gets displayed
devServer: {
contentBase: path.join(__dirname, env.server || '.'),
compress: true,
port: 9090,
hot: true,
// ...
},
plugins,
// list of additional plugins
/* Advanced configuration (click to show) */
};
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/liuyf2020/spriteJS.git
git@gitee.com:liuyf2020/spriteJS.git
liuyf2020
spriteJS
spriteJS
master

搜索帮助