Skip to content

Instantly share code, notes, and snippets.

@Domiii
Last active November 26, 2021 13:36
Show Gist options
  • Save Domiii/89245ff95f9c6e845e81865ee6607ee9 to your computer and use it in GitHub Desktop.
Save Domiii/89245ff95f9c6e845e81865ee6607ee9 to your computer and use it in GitHub Desktop.
Sample webpack build with Dbux
/**
* @file This config is supposed to be usable for many webpack build tasks, including `webpack/examples`.
* The following setup steps are for local development build on Windows.
*
* Setup:
yarn add --dev webpack-node-externals webpack webpack-cli
mkdir ..\..\node_modules\@dbux
mklink /J ..\..\node_modules\@dbux\babel-plugin ..\..\..\dbux\dbux-babel-plugin
mklink /J ..\..\node_modules\@dbux\runtime ..\..\..\dbux\dbux-runtime
* Non-local setup:
yarn add --dev webpack-node-externals webpack webpack-cli @dbux/babel-plugin @dbux/runtime
* Build:
* npx webpack
*
* Run:
* node ./dist/bundle.js
*
* Build -> Run:
* npx webpack && node ./dist/bundle.js
*
* @see https://gist.github.com/Domiii/89245ff95f9c6e845e81865ee6607ee9
*/
// /** */
// const nodeExternals = require('webpack-node-externals');
// eslint-disable-next-line node/no-extraneous-require
const makeInclude = require('@dbux/babel-plugin/dist/include').default;
/** ###########################################################################
* babel options
* ##########################################################################*/
const includeOptions = {
packageWhitelist: 'module1',
packageBlacklist: ''
};
const defaultBabelOptions = {
cacheDirectory: true,
cacheCompression: false,
// see https://github.com/webpack/webpack/issues/11510#issuecomment-696027212
sourceType: "unambiguous",
sourceMaps: true,
retainLines: true,
presets: [
// [
// '@babel/preset-env',
// {
// useBuiltIns: 'usage',
// corejs: 3
// }
// ]
],
plugins: [
'@dbux/babel-plugin'
]
};
/** ###########################################################################
* webpack config
* ##########################################################################*/
module.exports = {
target: 'node',
mode: 'development',
context: __dirname,
devtool: 'source-map',
/** ########################################
* entry
* #######################################*/
entry: {
bundle: './example.js'
},
/** ########################################
* output
* #######################################*/
output: {
filename: '[name].js',
library: {
type: 'commonjs'
}
},
module: {
rules: [
/** ########################################
* babel-loader
* #######################################*/
{
test: /\.js$/,
include: makeInclude(includeOptions),
use: [
{
loader: 'babel-loader',
options: defaultBabelOptions
}
],
// include: [
// ...srcFolders.map(folder => path.join(ProjectRoot, folder))
// ],
},
]
},
/** ###########################################################################
* externals
* ##########################################################################*/
externals: [
// nodeExternals(),
{
'@dbux/runtime': 'commonjs @dbux/runtime'
}
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment