Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "simplify webpack config" #333

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 52 additions & 43 deletions examples/webpack-minimal/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,62 @@ import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import WorkboxWebpackPlugin from 'workbox-webpack-plugin';
import { Configuration } from 'webpack';
import { tsImport } from 'tsx/esm/api'
import * as tsx from 'tsx/cjs/api'

const {default: UnpluginTypia} = tsx.require('../../packages/unplugin-typia/src/webpack.ts', __filename)

const isProduction = process.env.NODE_ENV == 'production';

module.exports = async () => {
/** we use tsImport because of development. However, in real-world projecct, just use `import` instead */
// const { default: UnpluginTypia } = await import('@ryoppippi/unplugin-typia/webpack');
const { default: UnpluginTypia } = await tsImport('@ryoppippi/unplugin-typia/webpack', __dirname);

return {
mode: isProduction ? 'production' : 'development',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
},
devServer: {
open: true,
host: 'localhost',
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
}),
UnpluginTypia(),
isProduction && new WorkboxWebpackPlugin.GenerateSW(),
// Add your plugins here
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
],
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
exclude: ['/node_modules/'],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset',
},
const config: Configuration = {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
},
devServer: {
open: true,
host: 'localhost',
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
}),
UnpluginTypia()
// Add your plugins here
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
],
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
exclude: ['/node_modules/'],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset',
},

// Add your rules for custom modules here
// Learn more about loaders from https://webpack.js.org/loaders/
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '...'],
},
} as const satisfies Configuration;
// Add your rules for custom modules here
// Learn more about loaders from https://webpack.js.org/loaders/
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '...'],
},
};

module.exports = () => {
if (isProduction) {
config.mode = 'production';

if (config.plugins == null) {
config.plugins = []
}
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());

} else {
config.mode = 'development';
}
return config;
};
28 changes: 17 additions & 11 deletions packages/unplugin-typia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,28 @@ Examples:

> ⚠️ Note: Currently, this plugin works only with 'esm' target.

> If you want to use 'cjs', use dynamic import.

> If you want to use 'cjs' target on Node < 20.17.0 , please use with [`jiti`](https://github.com/unjs/jiti).
> If you want to use 'cjs' target on Node >= 20.17.0, please use with `require` and enable [`--experimental-require-modules` flag](https://github.com/nodejs/node/pull/51977).
> If you want to use 'esm' target, don't worry! You can use this plugin without any additional setup.

```sh
npm install jiti
```

```js
// webpack.config.js

module.exports = async () => {
const { default: UnpluginTypia } = await import('@ryoppippi/unplugin-typia/webpack');
return {
plugins: [
new UnpluginTypia({
// options
}),
],
};
// if you use Node < 20.17.0
const jiti = require('jiti')(__filename);
const { default: UnpluginTypia } = jiti('@ryoppippi/unplugin-typia/webpack');

// if you use Node >= 20.17.0
// const { default: UnpluginTypia } = require("@ryoppippi/unplugin-typia/webpack");

module.exports = {
plugins: [
UnpluginTypia({ /* options */ }),
],
};
```

Expand Down
23 changes: 12 additions & 11 deletions packages/unplugin-typia/src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import unplugin from './core/index.js';
*
* Currently, this plugin works only with 'esm' target.
*
* If you want to use 'cjs' use dynamic import
* If you want to use 'cjs' target on Node < 20.17.0 , please use with [`jiti`](https://github.com/unjs/jiti).
* If you want to use 'cjs' target on Node >= 20.17.0, please use with `require` and enable [`--experimental-require-modules` flag](https://github.com/nodejs/node/pull/51977).
* If you want to use 'esm' target, don't worry! You can use this plugin without any additional setup.
*
* Refer this issue https://github.com/samchon/typia/issues/1094
Expand All @@ -20,16 +21,16 @@ import unplugin from './core/index.js';
* ```js
* // webpack.config.js
*
* module.exports = async () => {
* const { default: UnpluginTypia } = await import('@ryoppippi/unplugin-typia/webpack');
* return {
* plugins: [
* new UnpluginTypia({
* // options
* }),
* ],
* };
* };
* // if you use Node < 20.17.0
* const jiti = require("jiti")(__filename);
* const { default: UnpluginTypia } = jiti("@ryoppippi/unplugin-typia/webpack");
*
* // if you use Node >= 20.17.0
* const { default: UnpluginTypia } = require("@ryoppippi/unplugin-typia/webpack");
*
* module.exports = {
* plugins: [UnpluginTypia({ /* your config *\/ })],
* }
* ```
*
*/
Expand Down