Last active
December 30, 2021 08:27
-
-
Save siddharthvp/bc969a10a2f03e9ce5b5dddca6f9407a to your computer and use it in GitHub Desktop.
Webpack config for transpiling orange-i18n or banana-i18n to ES5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Webpack configuration to transpile ES module library to MW environment | |
// Run: | |
// $ npm i -D webpack webpack-cli @babel/core @babel/preset-env babel-loader | |
// $ npx webpack | |
// Find output in dist/banana-i18n.js | |
const path = require('path') | |
const TerserPlugin = require('terser-webpack-plugin') | |
module.exports = { | |
mode: 'production', | |
entry: './src/index.js', | |
target: ['web', 'es5'], | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'] | |
} | |
} | |
] | |
}, | |
optimization: { | |
minimizer: [ | |
new TerserPlugin({ | |
// Without ascii_only=true, MW minifier somehow mangles a regex in the output | |
// causing it to be invalid JavaScript | |
terserOptions: { output: { ascii_only: true } } | |
}) | |
] | |
}, | |
output: { | |
library: 'Banana', | |
libraryExport: 'default', | |
libraryTarget: 'umd', | |
globalObject: 'this', | |
filename: 'banana-i18n.js', | |
path: path.resolve(__dirname, 'dist') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment