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

120 lines
3.0 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');
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)/,
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$/,
2022-10-20 11:57:30 -04:00
include: ['ol', 'codemirror', '@toast-ui'].map(moduleNameToPath),
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
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(),
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: {
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',
},
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
},
};