2020-02-07 09:59:10 +08:00
|
|
|
const path = require('path')
|
2019-03-15 11:42:41 +08:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2019-09-20 20:12:59 +08:00
|
|
|
const TerserJSPlugin = require('terser-webpack-plugin')
|
2019-03-31 13:12:56 +08:00
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin')
|
2018-07-29 15:31:54 +08:00
|
|
|
|
2019-03-17 23:10:40 +08:00
|
|
|
const devMode = !process.argv.includes('-p')
|
2018-07-29 15:31:54 +08:00
|
|
|
|
2018-08-09 09:31:34 +08:00
|
|
|
/** @type {import('webpack').Configuration} */
|
2018-08-08 18:17:11 +08:00
|
|
|
const config = {
|
2019-03-15 11:42:41 +08:00
|
|
|
mode: devMode ? 'development' : 'production',
|
|
|
|
entry: {
|
2020-03-14 17:00:35 +08:00
|
|
|
app: ['react-hot-loader/patch', '@/index.tsx'],
|
2020-05-19 17:02:54 +08:00
|
|
|
sw: '@/scripts/sw.ts',
|
2020-05-18 16:40:31 +08:00
|
|
|
style: ['@/styles/common.css'],
|
2020-05-20 10:03:47 +08:00
|
|
|
home: '@/scripts/home-page.ts',
|
2020-02-01 12:44:39 +08:00
|
|
|
spectre: [
|
|
|
|
'spectre.css/dist/spectre.min.css',
|
2020-03-14 17:00:35 +08:00
|
|
|
'@/fonts/minecraft.css',
|
|
|
|
'@/styles/spectre.css',
|
2020-02-01 12:44:39 +08:00
|
|
|
],
|
2019-03-15 11:42:41 +08:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: `${__dirname}/public/app`,
|
2020-05-19 17:02:54 +08:00
|
|
|
filename: ({ chunk }) =>
|
|
|
|
chunk.name === 'sw'
|
|
|
|
? 'sw.js'
|
|
|
|
: devMode
|
|
|
|
? '[name].js'
|
|
|
|
: '[name].[contenthash:7].js',
|
2019-03-15 11:42:41 +08:00
|
|
|
chunkFilename: devMode ? '[id].js' : '[id].[contenthash:7].js',
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2020-01-16 16:14:49 +08:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2020-03-12 11:06:23 +08:00
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
configFile: 'tsconfig.build.json',
|
2020-03-18 11:00:32 +08:00
|
|
|
transpileOnly: true,
|
2020-03-12 11:06:23 +08:00
|
|
|
},
|
2020-01-16 16:14:49 +08:00
|
|
|
},
|
2020-03-14 17:00:35 +08:00
|
|
|
{
|
2020-05-18 16:40:31 +08:00
|
|
|
test: /\.css$/,
|
2020-03-14 17:00:35 +08:00
|
|
|
use: [
|
|
|
|
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
2020-05-18 16:40:31 +08:00
|
|
|
importLoaders: 1,
|
2020-03-14 17:00:35 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'postcss-loader',
|
2019-03-15 11:42:41 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2020-05-30 11:18:13 +08:00
|
|
|
test: /\.(png|webp)$/,
|
2019-03-15 11:42:41 +08:00
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 8192,
|
2019-02-19 17:26:38 +08:00
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(svg|woff2?|eot|ttf)$/,
|
2019-03-25 22:01:57 +08:00
|
|
|
loader: devMode ? 'url-loader' : 'file-loader',
|
2019-03-15 11:42:41 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
2019-03-31 13:29:23 +08:00
|
|
|
filename: devMode ? '[name].css' : '[name].[contenthash:7].css',
|
|
|
|
chunkFilename: devMode ? '[id].css' : '[id].[contenthash:7].css',
|
2019-03-15 11:42:41 +08:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
resolve: {
|
2020-05-15 11:31:30 +08:00
|
|
|
extensions: ['.js', '.ts', '.tsx', '.json'],
|
2020-01-21 10:22:20 +08:00
|
|
|
alias: {
|
|
|
|
'react-dom': '@hot-loader/react-dom',
|
2020-02-07 09:59:10 +08:00
|
|
|
'@': path.resolve(__dirname, 'resources/assets/src'),
|
2020-05-18 16:40:31 +08:00
|
|
|
readline: '@/scripts/cli/readline.ts',
|
2020-01-21 10:22:20 +08:00
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
},
|
2020-05-18 16:40:31 +08:00
|
|
|
externals: Object.assign(
|
|
|
|
{ jquery: 'jQuery', bootstrap: 'bootstrap', 'admin-lte': 'adminlte' },
|
|
|
|
devMode
|
|
|
|
? {}
|
|
|
|
: {
|
|
|
|
react: 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
|
|
|
},
|
|
|
|
),
|
2019-09-20 20:12:59 +08:00
|
|
|
optimization: {
|
2020-05-19 18:25:57 +08:00
|
|
|
minimizer: [new TerserJSPlugin({})],
|
2019-09-20 20:12:59 +08:00
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
devtool: devMode ? 'cheap-module-eval-source-map' : false,
|
|
|
|
devServer: {
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
2019-02-19 17:26:38 +08:00
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
host: '0.0.0.0',
|
|
|
|
hot: true,
|
2019-09-20 19:43:51 +08:00
|
|
|
hotOnly: true,
|
2019-03-15 11:42:41 +08:00
|
|
|
stats: 'errors-only',
|
|
|
|
},
|
2020-03-26 10:13:40 +08:00
|
|
|
stats: 'errors-only',
|
2020-03-22 12:21:17 +08:00
|
|
|
node: {
|
|
|
|
child_process: 'empty',
|
|
|
|
fs: 'empty',
|
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
}
|
2018-08-08 18:17:11 +08:00
|
|
|
|
2019-03-15 11:42:41 +08:00
|
|
|
if (devMode) {
|
2019-09-20 19:43:51 +08:00
|
|
|
config.plugins.push(new webpack.NamedModulesPlugin())
|
2019-03-15 11:42:41 +08:00
|
|
|
config.plugins.push(new webpack.HotModuleReplacementPlugin())
|
2019-02-19 17:26:38 +08:00
|
|
|
} else {
|
2019-09-20 19:43:51 +08:00
|
|
|
config.plugins.push(new ManifestPlugin())
|
2018-08-09 09:31:34 +08:00
|
|
|
}
|
|
|
|
|
2019-03-15 11:42:41 +08:00
|
|
|
module.exports = config
|