23 Star 228 Fork 41

Yami / cardjs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
webpack.config.js 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
yami 提交于 2022-02-12 19:53 . feat: node和浏览器端分开打包
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const env = process.env.NODE_ENV
const isDev = process.env.NODE_ENV === 'development'
const config = {
entry: {
browser: './source/index.js',
node: './source/index-node.js',
},
output: {
path: path.resolve(__dirname, 'packages'),
filename: '[name]/dist/index.js',
globalObject: 'this',
libraryTarget: 'umd'
},
mode: 'production',
module: {
rules: []
},
externals: {
'fs': 'fs',
'canvas': 'canvas',
'sqlite3': 'sqlite3',
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: __dirname + '/source/mold',
to: __dirname + '/packages/browser/dist/mold'
},
{
from: __dirname + '/source/config',
to: __dirname + '/packages/browser/dist/config'
},
{
from: __dirname + '/source/types',
to: __dirname + '/packages/browser/dist/types'
},
]
}),
new CopyWebpackPlugin({
patterns: [
{
from: __dirname + '/source/mold',
to: __dirname + '/packages/node/dist/mold'
},
{
from: __dirname + '/source/config',
to: __dirname + '/packages/node/dist/config'
},
{
from: __dirname + '/source/types',
to: __dirname + '/packages/node/dist/types'
},
]
}),
// new HtmlWebpackPlugin({
// filename: 'dev.html',
// template: 'dev.html',
// inject: true
// })
]
}
if (isDev) {
config.devServer = {
port: 8080,
host: 'localhost',
overlay: {
errors: true
},
open: true,
hot: true
}
// 添加热更新模块
config.plugins.push(
new webpack.DefinePlugin({
'process.evn': '"development"' //添加全局变量
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
config.devtool = '#cheap-module-eval-source-map'
}
module.exports = config
JavaScript
1
https://gitee.com/ymssx/cardjs.git
git@gitee.com:ymssx/cardjs.git
ymssx
cardjs
cardjs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891