1 Star 0 Fork 0

常拧螺丝 / battle-city

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
webpack.config.js 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
shinima 提交于 2018-11-03 01:06 . 调整 webpack 配置
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const packageInfo = require('./package.json')
const getDevConfig = require('./devConfig')
function getNow() {
const d = new Date()
const YYYY = d.getFullYear()
const MM = String(d.getMonth() + 1).padStart(2, '0')
const DD = String(d.getDate()).padStart(2, '0')
const HH = String(d.getHours()).padStart(2, '0')
const mm = String(d.getMinutes()).padStart(2, '0')
const ss = String(d.getSeconds()).padStart(2, '0')
return `${YYYY}-${MM}-${DD} ${HH}:${mm}:${ss}`
}
function processDevConfig(config) {
const result = {}
for (const [key, value] of Object.entries(config)) {
result[key] = JSON.stringify(value)
}
return result
}
module.exports = function(env = {}, argv) {
const prod = argv.mode === 'production'
const plugins = [
new webpack.DefinePlugin({
COMPILE_VERSION: JSON.stringify(packageInfo.version),
COMPILE_DATE: JSON.stringify(getNow()),
// 将 devConfig.js 中的配置数据加入到 DefinePlugin 中
...processDevConfig(getDevConfig(!prod)),
}),
new HtmlWebpackPlugin({
title: 'battle-city',
filename: 'index.html',
template: path.resolve(__dirname, `app/index.html`),
}),
!prod && new webpack.HotModuleReplacementPlugin(),
].filter(Boolean)
return {
context: __dirname,
target: 'web',
entry: [path.resolve(__dirname, 'app/main.tsx'), path.resolve(__dirname, 'app/polyfills.ts')],
output: {
path: path.resolve(__dirname, 'dist'),
filename: prod ? '[name]-[chunkhash:6].js' : '[name].js',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{ test: /\.json$/, type: 'javascript/auto', loader: 'json-loader' },
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
plugins: ['react-hot-loader/babel'],
},
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
plugins,
devServer: {
contentBase: __dirname,
hot: true,
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/donglongqin/battle-city.git
git@gitee.com:donglongqin/battle-city.git
donglongqin
battle-city
battle-city
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891