ampcast/webpack.config.js

93 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-07-20 09:29:42 +08:00
const {resolve} = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
2021-07-19 08:47:37 +08:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2022-11-13 09:48:34 +08:00
const devKeys = require('../credentials/keys-dev.json');
const prodKeys = require('../credentials/keys-prod.json');
2021-07-20 09:29:42 +08:00
const packageJson = require('./package.json');
2021-07-19 08:47:37 +08:00
2021-07-20 09:29:42 +08:00
module.exports = (env) => {
const mode = env.mode || 'production';
const __dev__ = mode === 'development';
const wwwDir = resolve(__dirname, __dev__ ? 'www-dev' : 'www');
2022-11-13 09:48:34 +08:00
const keys = __dev__ ? devKeys : prodKeys;
2021-07-19 08:47:37 +08:00
2021-07-20 09:29:42 +08:00
return {
entry: './src/index.tsx',
output: {
filename: 'bundle.js',
path: wwwDir,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
2022-11-20 23:57:10 +08:00
{
loader: 'postcss-loader',
},
2021-07-20 09:29:42 +08:00
],
},
2022-08-27 02:39:31 +08:00
{
test: /\.frag$/,
type: 'asset/source',
},
2021-07-20 09:29:42 +08:00
],
},
plugins: [
new ESLintPlugin({
extensions: ['.tsx', '.ts'],
}),
new MiniCssExtractPlugin({
filename: 'bundle.css',
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
__dev__,
__app_name__: JSON.stringify(packageJson.name),
__app_version__: JSON.stringify(packageJson.version),
2022-10-25 07:11:17 +08:00
__app_contact__: JSON.stringify(packageJson.author.email),
2022-11-13 09:48:34 +08:00
__am_dev_token__: JSON.stringify(keys.am_dev_token),
__lf_api_key__: JSON.stringify(keys.lf_api_key),
__lf_api_secret__: JSON.stringify(keys.lf_api_secret),
__sp_client_id__: JSON.stringify(keys.sp_client_id),
__yt_api_key__: JSON.stringify(keys.yt_api_key),
__yt_client_id__: JSON.stringify(keys.yt_client_id),
2021-07-20 09:29:42 +08:00
}),
2021-07-19 08:47:37 +08:00
],
2021-07-20 09:29:42 +08:00
resolve: {
alias: {
assets: resolve(__dirname, 'src/assets/'),
components: resolve(__dirname, 'src/components/'),
hooks: resolve(__dirname, 'src/hooks/'),
services: resolve(__dirname, 'src/services/'),
styles: resolve(__dirname, 'src/styles/'),
types: resolve(__dirname, 'src/types/'),
utils: resolve(__dirname, 'src/utils/'),
},
extensions: ['.tsx', '.ts', '.js'],
},
stats: {
builtAt: true,
},
mode,
};
};