Skip to content

Commit 0b8558b

Browse files
committed
ci: 去掉vuecli 手撸webpack 进度 serve
1 parent 9c5533d commit 0b8558b

File tree

5 files changed

+4333
-7933
lines changed

5 files changed

+4333
-7933
lines changed

babel.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
presets: ['@vue/app']
2+
presets: ['@babel/preset-env'],
3+
plugins: [
4+
'@babel/transform-runtime'
5+
]
36
};

build/webpack.config.js

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const webpack = require('webpack');
4+
const VueLoaderPlugin = require('vue-loader/lib/plugin');
5+
6+
const MarkdownItContainer = require('markdown-it-container');
7+
const MarkdownItCheckBox = require('markdown-it-task-checkbox');
8+
const MarkdownItDec = require('markdown-it-decorate');
9+
/**
10+
* 增加 hljs 的 classname
11+
*/
12+
const wrapCustomClass = function (render) {
13+
return function (...args) {
14+
return render(...args)
15+
.replace('<code class="', '<code class="hljs ')
16+
.replace('<code>', '<code class="hljs">');
17+
};
18+
};
19+
20+
const vueMarkdown = {
21+
raw: true,
22+
// 定义处理规则
23+
preprocess: function (MarkdownIt, source) {
24+
// 表格
25+
MarkdownIt.renderer.rules.table_open = function () {
26+
return '<table class="table">';
27+
};
28+
29+
// ```html``` 给这种样式加个class hljs
30+
MarkdownIt.renderer.rules.fence = wrapCustomClass(
31+
MarkdownIt.renderer.rules.fence
32+
);
33+
// ```code``` 给这种样式加个class code_inline
34+
const codeInline = MarkdownIt.renderer.rules.code_inline;
35+
MarkdownIt.renderer.rules.code_inline = function (...args) {
36+
args[0][args[1]].attrJoin('class', 'code_inline');
37+
return codeInline(...args);
38+
};
39+
return source;
40+
},
41+
use: [
42+
// 'markdown-it-container'的作用是自定义代码块
43+
[
44+
MarkdownItContainer,
45+
'demo',
46+
{
47+
validate: params => params.trim().match(/^demo\s*(.*)$/),
48+
render: function (tokens, idx) {
49+
if (tokens[idx].nesting === 1) {
50+
return `<demo-block>
51+
<div slot="highlight">`;
52+
}
53+
return '</div></demo-block>\n';
54+
}
55+
}
56+
],
57+
[require('markdown-it-container'), 'tip'],
58+
[require('markdown-it-container'), 'warning'],
59+
[
60+
MarkdownItCheckBox,
61+
{
62+
disabled: true
63+
}
64+
],
65+
[MarkdownItDec]
66+
]
67+
};
68+
69+
module.exports = {
70+
mode: 'development',
71+
entry: {
72+
main: path.resolve(__dirname, '../src/main.js')
73+
},
74+
output: {
75+
filename: 'js/[name].[hash:8].js',
76+
path: path.resolve(__dirname, 'dist'),
77+
chunkFilename: 'js/[name].[hash:8].js',
78+
publicPath: process.env.NODE_ENV === 'production'
79+
? 'http://cdn.jskou.com/'
80+
: '/'
81+
},
82+
devServer: {
83+
hot: true,
84+
port: 3000,
85+
contentBase: './dist'
86+
},
87+
resolve: {
88+
alias: {
89+
vue$: 'vue/dist/vue.runtime.esm.js',
90+
'@': path.resolve(__dirname, '../src')
91+
},
92+
extensions: [
93+
'.mjs',
94+
'.js',
95+
'.jsx',
96+
'.vue',
97+
'.json',
98+
'.wasm'
99+
]
100+
},
101+
module: {
102+
rules: [
103+
{
104+
test: /\.md$/,
105+
use: [
106+
{
107+
loader: 'vue-loader',
108+
options: {
109+
compilerOptions: {
110+
preserveWhitespace: false
111+
}
112+
}
113+
},
114+
{
115+
loader: 'vue-markdown-loader/lib/markdown-compiler',
116+
options: vueMarkdown
117+
}
118+
]
119+
},
120+
{
121+
test: /\.vue$/,
122+
use: [
123+
{
124+
loader: 'cache-loader'
125+
},
126+
{
127+
loader: 'thread-loader'
128+
},
129+
{
130+
loader: 'vue-loader',
131+
options: {
132+
compilerOptions: {
133+
preserveWhitespace: false
134+
}
135+
}
136+
}
137+
]
138+
},
139+
{
140+
test: /\.(js|jsx)$/,
141+
exclude: /node_modules/,
142+
use: [
143+
{
144+
loader: 'babel-loader'
145+
}
146+
]
147+
},
148+
{
149+
test: /\.css$/,
150+
use: [
151+
{
152+
loader: 'style-loader'
153+
},
154+
{
155+
loader: 'css-loader'
156+
}
157+
]
158+
},
159+
{
160+
test: /\.(jpe?g|png|gif|svg)$/i,
161+
use: [
162+
{
163+
loader: 'url-loader',
164+
options: {
165+
limit: 4096,
166+
fallback: {
167+
loader: 'file-loader',
168+
options: {
169+
name: 'img/[name].[hash:8].[ext]'
170+
}
171+
}
172+
}
173+
}
174+
]
175+
},
176+
{
177+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
178+
use: [
179+
{
180+
loader: 'url-loader',
181+
options: {
182+
limit: 4096,
183+
fallback: {
184+
loader: 'file-loader',
185+
options: {
186+
name: 'fonts/[name].[hash:8].[ext]'
187+
}
188+
}
189+
}
190+
}
191+
]
192+
}
193+
]
194+
},
195+
plugins: [
196+
new VueLoaderPlugin(),
197+
new webpack.DefinePlugin({
198+
'process.env': {
199+
BASE_URL: JSON.stringify('/')
200+
}
201+
}),
202+
new HtmlWebpackPlugin({
203+
template: path.resolve(__dirname, '../public/index.html')
204+
}),
205+
new webpack.NamedModulesPlugin(),
206+
new webpack.HotModuleReplacementPlugin()
207+
208+
]
209+
};

0 commit comments

Comments
 (0)