-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Plugin to bundle source from input paths
BREAKING CHANGE: First Release
- Loading branch information
0 parents
commit ee64073
Showing
20 changed files
with
6,766 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
} |
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
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"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/fermium |
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
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" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
save-prefix "" |
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
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. |
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
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'] | ||
) | ||
] | ||
} | ||
``` |
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
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" | ||
} | ||
} |
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
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') | ||
}), | ||
], | ||
}; |
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
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) | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Yeah Script1') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Yeah Script2') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Test Script') |
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
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.') |
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
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')] | ||
} | ||
} |
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
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"] | ||
} |
Oops, something went wrong.