Skip to content

Commit

Permalink
Merge pull request #117 from ecosia/different-outputs
Browse files Browse the repository at this point in the history
Provide ESM next to CJS builds
  • Loading branch information
nasrinaria committed Oct 5, 2023
2 parents 452beca + 95bf878 commit 181c571
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "vue-safe-html",
"version": "2.2.0",
"description": "A Vue directive which renders sanitised HTML dynamically",
"main": "dist/main.js",
"main": "dist/main.common.js",
"module": "dist/main.esm.js",
"repository": "git@github.com:ecosia/vue-safe-html.git",
"author": "Ecosia GmbH <opensource@ecosia.org>",
"contributors": [
Expand Down
62 changes: 40 additions & 22 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
const { resolve } = require('path');

module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: resolve(__dirname, 'dist'),
library: 'VueSafeHTML',
libraryTarget: 'umd',
globalObject: '(typeof self !== \'undefined\' ? self : this)',
},
mode: 'production',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
const _module = {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
],
},
},
],
};

module.exports = [
{
entry: './src/index.js',
output: {
filename: 'main.common.js',
path: resolve(__dirname, 'dist'),
library: 'VueSafeHTML',
libraryTarget: 'commonjs2',
globalObject: '(typeof self !== \'undefined\' ? self : this)',
},
mode: 'production',
module: _module,
},
{
entry: './src/index.js',
output: {
filename: 'main.esm.js',
path: resolve(__dirname, 'dist'),
libraryTarget: 'module',
globalObject: '(typeof self !== \'undefined\' ? self : this)',
},
mode: 'production',
experiments: {
outputModule: true, // Enable the "experiments.outputModule" option
},
module: _module,
},
];

0 comments on commit 181c571

Please sign in to comment.