Skip to content

Commit

Permalink
build: build everything from webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jan 23, 2022
1 parent 8415f44 commit f160428
Show file tree
Hide file tree
Showing 12 changed files with 6,357 additions and 3,706 deletions.
25 changes: 20 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
/node_modules
# Javascript
coverage
node_modules

/umd
/cjs
/esm
/dist
/types

# Random
/ignore
/docs
/esm
/cjs
/umd
*.log

# Vscode
.vscode/*
!.vscode/launch.json

# Npm & Yarn
package-lock.json
.yarn/*
!.yarn/releases
!.yarn/plugins
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ Licensed under the **MIT**. See [`LICENSE`](LICENSE) for more informations.

<br />


[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor?ref=badge_large)

## Contact

See my contact information on my [github profile](https://github.com/arthurfiorette) or
open a new issue.

<br />
<br />
11 changes: 8 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

echo "\nStarting build...\n"

rm -rf cjs/ esm/ umd/
rm -rf cjs/ esm/ umd/ types/
mkdir cjs/ esm/ umd/ types/

echo "Target cleared...\n"

webpack --config build/webpack.config.js &
tsc -p build/tsconfig.cjs.json &
tsc -p build/tsconfig.esm.json &
tsc -p build/tsconfig.types.json &
echo "export * from '../types';" | tee \
esm/index.d.ts esm/dev.d.ts \
cjs/index.d.ts cjs/dev.d.ts \
umd/index.d.ts umd/dev.d.ts umd/es6.d.ts \
> /dev/null &

wait

Expand Down
5 changes: 4 additions & 1 deletion build/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
echo "\nStarting checking...\n"

es-check es5 umd/es5.js &
es-check es6 umd/es6.js &
es-check es6 umd/index.js cjs/index.js &
es-check es2017 umd/dev.js cjs/dev.js &
es-check es2017 esm/dev.js --module &
es-check es6 esm/index.js --module &

wait

Expand Down
1 change: 0 additions & 1 deletion build/tsconfig.umd.json → build/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"module": "ESNext", // webpack converts to UMD
"target": "ESNext",
"outDir": "../umd",

// Emits all import helpers as an import to tslib
// This allows webpack to be better at tree shaking
Expand Down
9 changes: 0 additions & 9 deletions build/tsconfig.cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions build/tsconfig.esm.json

This file was deleted.

10 changes: 10 additions & 0 deletions build/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"outDir": "../types",
"declaration": true,
"declarationMap": true
},
"include": ["../src"]
}
97 changes: 80 additions & 17 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@

const path = require('path');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const { DefinePlugin } = require('webpack');

const root = (...p) => path.resolve(__dirname, '..', ...p);

/**
* @param {{
* output: string;
* esTarget: string;
* libraryType: import('webpack').LibraryOptions['type'];
* libraryName?: import('webpack').LibraryOptions['name'];
* inlineDeps?: boolean;
* devBuild?: boolean;
* }} options
* @returns {import('webpack').Configuration}
*/
const config = ({ output, esTarget }) => ({
const config = ({
output,
esTarget,
libraryType,
libraryName,
inlineDeps = false,
devBuild = false
}) => ({
mode: 'production',

entry: root('src', 'index.ts'),
Expand All @@ -23,20 +35,27 @@ const config = ({ output, esTarget }) => ({
globalObject: `typeof self !== 'undefined' ? self : this`,
filename: output + '.js',
sourceMapFilename: output + '.map',
chunkFormat: 'module',
module: libraryType === 'module',
library: {
type: 'umd',
name: 'AxiosCacheInterceptor'
},
chunkFormat: 'module'
type: libraryType,
name: libraryName
}
},

target: esTarget,
devtool: devBuild ? 'source-map' : false,

resolve: {
extensions: ['.ts', '.js']
},
experiments: { outputModule: true },
resolve: { extensions: ['.ts', '.js'] },

devtool: 'source-map',
externals: inlineDeps
? {
'cache-parser': 'cache-parser',
'object-code': 'object-code',
'fast-defer': 'fast-defer'
}
: undefined,

module: {
rules: [
Expand All @@ -45,7 +64,7 @@ const config = ({ output, esTarget }) => ({
test: /\.(ts|js)$/,
loader: 'ts-loader',
options: {
configFile: root('build', 'tsconfig.umd.json'),
configFile: root('build', 'tsconfig.build.json'),
compilerOptions: {
target: esTarget
}
Expand All @@ -55,22 +74,66 @@ const config = ({ output, esTarget }) => ({
},

optimization: {
minimize: true,
minimize: !devBuild,
sideEffects: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
concatenateModules: true,
minimizer: [new TerserWebpackPlugin({ parallel: true })]
}
},

plugins: [new DefinePlugin({ __DEV__: devBuild })]
});

module.exports = [
// ESModule
config({
esTarget: 'es2015', //es6
output: 'umd/es6'
esTarget: 'es2015',
output: 'esm/index',
libraryType: 'module',
inlineDeps: true
}),
config({
esTarget: 'es5',
output: 'umd/es5'
esTarget: 'es2017',
output: 'esm/dev',
libraryType: 'module',
inlineDeps: true,
devBuild: true
}),

// CommonJS
config({
esTarget: 'es2015',
output: 'cjs/index',
libraryType: 'commonjs2',
inlineDeps: true
}),
config({
esTarget: 'es2017',
output: 'umd/index'
output: 'cjs/dev',
libraryType: 'commonjs2',
inlineDeps: true,
devBuild: true
}),

// UMD
config({
esTarget: 'es2015',
output: 'umd/index',
libraryType: 'umd',
libraryName: 'AxiosCacheInterceptor'
}),
config({
esTarget: 'es2017',
output: 'umd/dev',
libraryType: 'umd',
libraryName: 'AxiosCacheInterceptor',
devBuild: true
}),
config({
esTarget: 'es5',
output: 'umd/es5',
libraryType: 'umd',
libraryName: 'AxiosCacheInterceptor'
})
];
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"types": "./cjs/index.d.ts",
"module": "./esm/index.js",
"exports": {
"import": "./esm/index.js",
"require": "./cjs/index.js",
"default": "./umd/es6.js"
"import": "./esm/index.js",
"require": "./cjs/index.js",
"default": "./umd/index.js"
},
"browser": "./umd/es6.js",
"jsdelivr": "./umd/es6.js",
"unpkg": "./umd/es6.js",
"browser": "./umd/index.js",
"jsdelivr": "./umd/index.js",
"unpkg": "./umd/index.js",
"sideEffects": false,
"runkitExampleFilename": "./examples/runkit.js",
"scripts": {
Expand Down Expand Up @@ -44,6 +44,7 @@
"cjs/",
"esm/",
"src/",
"types/",
"examples/"
],
"author": {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
"newLine": "lf" /* Set the newline character for emitting files. */,
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
"stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
Expand Down
Loading

0 comments on commit f160428

Please sign in to comment.