static-cms/packages/core/webpack.config.js

125 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-09-30 06:13:47 -06:00
const path = require('path');
const webpack = require('webpack');
2022-10-20 11:57:30 -04:00
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
2023-03-30 13:29:09 -04:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2022-09-30 06:13:47 -06:00
const isProduction = process.env.NODE_ENV === 'production';
2022-10-02 20:06:20 -04:00
const devServerPort = parseInt(process.env.STATIC_CMS_DEV_SERVER_PORT || `${8080}`);
2022-09-30 06:13:47 -06:00
function moduleNameToPath(libName) {
return path.resolve(__dirname, '..', '..', 'node_modules', libName);
2022-09-30 06:13:47 -06:00
}
module.exports = {
2022-10-20 11:57:30 -04:00
entry: './src/index.ts',
2022-09-30 06:13:47 -06:00
mode: isProduction ? 'production' : 'development',
devtool: 'source-map',
externals: isProduction
? {
react: 'react',
'react-dom': 'react-dom',
}
: {},
2022-09-30 06:13:47 -06:00
module: {
rules: [
{
test: /\.m?js$/,
2022-10-20 11:57:30 -04:00
enforce: 'pre',
use: ['source-map-loader'],
exclude: [
/(node_modules[\\/]@toast-ui[\\/]editor[\\/]dist)/,
/(node_modules[\\/]nth-check[\\/]lib)/,
/(node_modules[\\/]minimatch[\\/]dist)/,
2023-01-03 11:40:38 -05:00
/(src[\\/]formats[\\/]util)/,
],
2022-09-30 06:13:47 -06:00
},
{
2022-10-20 11:57:30 -04:00
test: /\.m?js$/,
resolve: {
fullySpecified: false, // disable the behavior
},
},
{
2023-01-03 11:40:38 -05:00
test: /\.[jt]sx?$/,
2022-10-20 11:57:30 -04:00
use: [
{
loader: 'babel-loader',
options: {
plugins: [!isProduction && 'react-refresh/babel'].filter(Boolean),
},
},
],
2022-09-30 06:13:47 -06:00
exclude: /node_modules/,
},
{
test: /\.css$/,
2023-04-04 15:12:32 -04:00
include: [
...['ol', 'codemirror', '@toast-ui'].map(moduleNameToPath),
path.resolve(__dirname, 'src'),
],
2022-10-20 11:57:30 -04:00
use: [
2023-03-30 13:29:09 -04:00
!isProduction ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
2022-10-20 11:57:30 -04:00
],
2022-09-30 06:13:47 -06:00
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
rootMode: 'upward',
},
},
{
loader: 'react-svg-loader',
options: {
jsx: true, // true outputs JSX tags
},
},
],
},
],
},
resolve: {
plugins: [new TsconfigPathsPlugin({})],
2022-10-20 11:57:30 -04:00
extensions: ['.tsx', '.ts', '.jsx', '.js'],
2022-09-30 06:13:47 -06:00
fallback: {
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer/'),
},
},
plugins: [
2022-10-20 11:57:30 -04:00
!isProduction && new ReactRefreshWebpackPlugin(),
2023-03-30 13:29:09 -04:00
isProduction && new MiniCssExtractPlugin(),
2022-09-30 06:13:47 -06:00
new webpack.IgnorePlugin({ resourceRegExp: /^esprima$/ }),
new webpack.IgnorePlugin({ resourceRegExp: /moment\/locale\// }),
new webpack.ProvidePlugin({
2022-10-20 11:57:30 -04:00
process: 'process/browser',
2022-09-30 06:13:47 -06:00
Buffer: ['buffer', 'Buffer'],
}),
2022-10-20 11:57:30 -04:00
].filter(Boolean),
2022-09-30 06:13:47 -06:00
output: {
2023-01-29 09:50:51 -05:00
publicPath: '',
2022-09-30 06:13:47 -06:00
path: path.resolve(__dirname, 'dist'),
2022-10-02 20:06:20 -04:00
filename: 'static-cms-core.js',
2022-09-30 06:13:47 -06:00
library: {
2022-10-02 20:06:20 -04:00
name: 'StaticCmsCore',
2022-09-30 06:13:47 -06:00
type: 'umd',
},
},
devServer: {
static: {
directory: './dev-test',
2023-04-04 15:12:32 -04:00
watch: false,
2022-09-30 06:13:47 -06:00
},
host: '0.0.0.0',
port: devServerPort,
2022-10-20 11:57:30 -04:00
hot: true,
2022-09-30 06:13:47 -06:00
},
};