Skip to content

Commit

Permalink
feat: Plugin to bundle source from input paths
Browse files Browse the repository at this point in the history
BREAKING CHANGE: First Release
  • Loading branch information
ReiiYuki committed Jan 26, 2022
0 parents commit ee64073
Show file tree
Hide file tree
Showing 20 changed files with 6,766 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release
on:
push:
branches:
- master

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
logs
*.log
npm-debug.log*
.DS_Store

coverage
node_modules
build
.env.local
.env.development.local
.env.test.local
.env.production.local

*.cache
.env
5 changes: 5 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{ts,js}": ["prettier --write", "eslint --fix", "git add"],
"*.svg": ["svgo", "git add"]
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/fermium
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"bracketSpacing": true,
"jsxBracketSameLine": false,
"printWidth": 100,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": true,
"arrowParens": "avoid"
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-prefix ""
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 LINE MAN Wongnai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Bundle More Webpack Plugin

[![semantic-release](https://img.shields.io/badge/semantic-release-e10079.svg?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
![ts](https://badgen.net/badge/Built%20With/TypeScript/blue) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Webpack Plugin to bundle extra sources to your app.

## Installation

```
yarn add --dev bundle-more-webpack-plugin
```

### Usage

#### In your webpack config

```js
const { BundleMoreWebpackPlugin } = require('bundle-more-webpack-plugin')

module.exports = {
...
plugins: [
...,
new BundleMoreWebpackPlugin(
['file-path-to-bundle']
)
]
}
```
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "bundle-more-webpack-plugin",
"version": "0.0.0",
"main": "build/index.js",
"entry": "src/index.ts",
"deploy": "build",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/wongnai/bundle-more-webpack-plugin.git"
},
"homepage": "https://github.com/wongnai/bundle-more-webpack-plugin#readme",
"scripts": {
"build": "rollup -c",
"lint": "eslint --ext .ts,.js --quiet",
"test": "yarn build && webpack --config ./test/webpack.config.js && node ./test/test-bundle.js"
},
"devDependencies": {
"@rollup/plugin-commonjs": "19.0.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.0.0",
"@rollup/plugin-typescript": "8.3.0",
"@types/node": "16.11.6",
"@types/webpack": "4",
"@types/webpack-env": "1.16.3",
"eslint": "7.28.0",
"eslint-config-standard": "16.0.3",
"husky": "6.0.0",
"lint-staged": "11.0.0",
"prettier": "2.3.1",
"rollup": "2.51.0",
"rollup-plugin-cleaner": "1.0.0",
"rollup-plugin-includepaths": "0.2.4",
"rollup-plugin-visualizer": "5.5.0",
"semantic-release": "18.0.0",
"typescript": "4.4.4",
"webpack": "4",
"webpack-cli": "4.9.1"
},
"dependencies": {
"webpack-inject-plugin": "1.5.5"
}
}
33 changes: 33 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'path'

import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import visualizer from 'rollup-plugin-visualizer'

import config from './package.json'

export default {
input: config.entry,
external: [
'webpack-inject-plugin'
],
output: {
dir: config.deploy,
format: 'cjs',
sourcemap: true,
},
plugins: [
resolve(),
commonjs(),
typescript({
outDir: config.deploy,
declaration: true,
}),
json(),
visualizer({
filename: path.resolve(config.deploy, 'stat.html')
}),
],
};
21 changes: 21 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Webpack from 'webpack'
import InjectPlugin from 'webpack-inject-plugin'
import fs from 'fs'

const PLUGIN_NAME = 'BundleMoreWebpackPlugin'

export class BundleMoreWebpackPlugin{
paths: string[]

constructor(paths: string[]) {
this.paths = paths
}

apply(compiler: Webpack.Compiler) {
this.paths.forEach(path => {
new InjectPlugin(() => {
return fs.readFileSync(path, 'utf8')
}).apply(compiler)
})
}
}
1 change: 1 addition & 0 deletions test/externals/script1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Yeah Script1')
1 change: 1 addition & 0 deletions test/externals/script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Yeah Script2')
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Test Script')
19 changes: 19 additions & 0 deletions test/test-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs')
const path = require('path')

const rootPath = process.cwd()
const buildScriptPath = path.join('build', 'index.js')
const testPath = path.join(rootPath, 'test')
const outputScriptPath = path.join(testPath, buildScriptPath)

const outputText = fs.readFileSync(outputScriptPath).toString()

if (!outputText.includes('./test/index.js')) {
throw new Error('No input source found in build')
}

if (!outputText.includes("console.log('Yeah Script1')") || !outputText.includes("console.log('Yeah Script2')")) {
throw new Error('No external bundle paths source found in build')
}

console.log('This plugin is fine to be used.')
22 changes: 22 additions & 0 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const path = require('path')
const { BundleMoreWebpackPlugin } = require('../build')

module.exports = {
entry: path.resolve(__dirname, 'index.js'),
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'build')
},
plugins: [
new BundleMoreWebpackPlugin([
path.resolve(__dirname, 'externals', 'script1.js'),
path.resolve(__dirname, 'externals', 'script2.js')
]),
],
target: 'node',
mode: 'development',
devtool: false,
resolve: {
modules: [path.resolve(__dirname, 'externals')]
}
}
28 changes: 28 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"baseUrl": "./src",
"outDir": "dist",
"module": "esnext",
"target": "es6",
"lib": ["es6", "esnext"],
"allowJs": true,
"moduleResolution": "node",
"rootDirs": ["src"],
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noUnusedLocals": false,
"experimentalDecorators": true,
"importHelpers": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false, // NOTE: ทำไมเอาออก - ref. https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables
"types": ["node", "webpack-env"]
},
"include": ["src/**/*", "src/*"],
"exclude": ["node_modules", "dist", "public"]
}
Loading

0 comments on commit ee64073

Please sign in to comment.