Skip to content

Commit ab17a22

Browse files
committed
feat: add webpack example
1 parent ec8df93 commit ab17a22

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
public/bundle.*
4+
package-lock.json
5+
yarn.lock
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "example-svelte-webpack",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"cross-env": "^5.2.0",
6+
"css-loader": "^2.1.1",
7+
"mini-css-extract-plugin": "^0.6.0",
8+
"serve": "^11.0.0",
9+
"style-loader": "^0.23.1",
10+
"svelte": "^3.0.0",
11+
"svelte-loader": "2.13.3",
12+
"webpack": "^4.30.0",
13+
"webpack-cli": "^3.3.0",
14+
"webpack-dev-server": "^3.3.1"
15+
},
16+
"scripts": {
17+
"build": "cross-env NODE_ENV=production webpack",
18+
"dev": "webpack-dev-server --content-base public"
19+
}
20+
}
3.05 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf8" />
5+
<meta name="viewport" content="width=device-width" />
6+
7+
<title>Svelte app</title>
8+
9+
<link rel="icon" type="image/png" href="favicon.png" />
10+
<link
11+
rel="stylesheet"
12+
href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css"
13+
/>
14+
<link rel="stylesheet" href="bundle.css" />
15+
</head>
16+
17+
<body>
18+
<script src="bundle.js"></script>
19+
</body>
20+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script>
2+
import { onMount } from 'svelte';
3+
import { Editor } from 'bytemd';
4+
import remarkMath from 'remark-math';
5+
import rehypeKatex from 'rehype-katex';
6+
import rehypeHighlight from 'rehype-highlight';
7+
8+
let value = '';
9+
10+
function handleChange(e) {
11+
value = e.detail.value;
12+
}
13+
14+
let plugins = [];
15+
16+
onMount(async () => {
17+
const res = await fetch(
18+
'https://raw.githubusercontent.com/bytedance/bytemd/master/packages/example/src/demo.md'
19+
);
20+
const text = await res.text();
21+
value = text;
22+
});
23+
</script>
24+
25+
<style>
26+
:global(.bytemd) {
27+
height: 90vh !important;
28+
}
29+
</style>
30+
31+
<Editor
32+
{value}
33+
on:change={(v) => {
34+
value = v;
35+
}}
36+
{plugins}
37+
on:change={handleChange} />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'bytemd/dist/index.css';
2+
import 'highlight.js/styles/vs.css';
3+
// import 'github-markdown-css';
4+
import App from './App.svelte';
5+
6+
const app = new App({
7+
target: document.body,
8+
});
9+
10+
export default app;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2+
const path = require('path');
3+
4+
const mode = process.env.NODE_ENV || 'development';
5+
const prod = mode === 'production';
6+
7+
module.exports = {
8+
entry: {
9+
bundle: ['./src/main.js'],
10+
},
11+
resolve: {
12+
alias: {
13+
svelte: path.resolve('../../node_modules/svelte'),
14+
},
15+
extensions: ['.mjs', '.js', '.svelte'],
16+
mainFields: ['svelte', 'browser', 'module', 'main'],
17+
},
18+
output: {
19+
path: __dirname + '/public',
20+
filename: '[name].js',
21+
chunkFilename: '[name].[id].js',
22+
},
23+
module: {
24+
rules: [
25+
{
26+
test: /\.svelte$/,
27+
use: {
28+
loader: 'svelte-loader',
29+
options: {
30+
emitCss: true,
31+
hotReload: true,
32+
},
33+
},
34+
},
35+
{
36+
test: /\.css$/,
37+
use: [
38+
/**
39+
* MiniCssExtractPlugin doesn't support HMR.
40+
* For developing, use 'style-loader' instead.
41+
* */
42+
prod ? MiniCssExtractPlugin.loader : 'style-loader',
43+
'css-loader',
44+
],
45+
},
46+
],
47+
},
48+
mode,
49+
plugins: [
50+
new MiniCssExtractPlugin({
51+
filename: '[name].css',
52+
}),
53+
],
54+
devtool: prod ? false : 'source-map',
55+
};

0 commit comments

Comments
 (0)