Skip to content

Commit

Permalink
feat: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Amour1688 committed Jan 1, 2021
1 parent 61d4e00 commit d5a0f03
Show file tree
Hide file tree
Showing 6 changed files with 4,027 additions and 52 deletions.
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { createApp } from 'vue';

15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"description": "Tweak Vue components written in JSX in real time.",
"main": "dist/index.js",
"scripts": {},
"scripts": {
"build": "tsc"
},
"files": [
"dist"
],
Expand All @@ -24,13 +26,20 @@
"homepage": "https://github.com/Amour1688/vue-jsx-hot-loader#readme",
"dependencies": {
"@babel/parser": "^7.0.0",
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.0.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"devDependencies": {
"@types/webpack": "^4.41.22",
"@babel/core": "^7.12.10",
"@types/loader-utils": "^2.0.1",
"@vue/babel-plugin-jsx": "^1.0.0",
"babel-loader": "^8.2.2",
"jest": "^26.6.3",
"typescript": "^4.0.3",
"webpack": "^4.44.2"
"vue": "^3.0.5",
"webpack": "^4.44.2",
"webpack-dev-server": "^3.11.1"
}
}
34 changes: 29 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import webpack from 'webpack';
import * as webpack from 'webpack';
import * as hash from 'hash-sum';
import * as path from 'path';
import * as loaderUtils from 'loader-utils';
import * as parser from "@babel/parser";
import traverse from "@babel/traverse";

export default function loader(
this: webpack.loader.LoaderContext,
source: string
): string {
source: string,
sourceMap: string
) {
const loaderContext = this;

return source;

loaderContext.cacheable?.();
const webpackRemainingChain = loaderUtils.getRemainingRequest(loaderContext).split('!');
const fullPath = webpackRemainingChain[webpackRemainingChain.length - 1];
const filename = path.relative(process.cwd(), fullPath);
const hotId = hash(fullPath);

loaderContext.callback(
null,
`${source}
/* hot reload */
if (module.hot) {
script.__hmrId = "${hotId}"
const api = __VUE_HMR_RUNTIME__
module.hot.accept()
if (!api.createRecord('${hotId}')) {
api.reload('${hotId}', script)
}
}
`,
sourceMap
);
};
1 change: 1 addition & 0 deletions src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'hash-sum'
21 changes: 21 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const babelConfig = {
plugins: [
'@vue/babel-plugin-jsx'
],
}

module.exports = {
mode: 'development',
entry: {
app: './examples/index.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
options: babelConfig,
}
],
},
};
Loading

0 comments on commit d5a0f03

Please sign in to comment.