forked from ustbhuangyi/vue-3.x-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (65 loc) · 1.76 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
module.exports = {
mode: 'development',
entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
const fullDir = path.join(__dirname, dir)
const entry = path.join(fullDir, 'app.js')
if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
entries[dir] = ['webpack-hot-middleware/client', entry]
}
return entries
}, {}),
/**
* 根据不同的目录名称,打包生成目标 js,名称和目录名一致
*/
output: {
path: path.join(__dirname, '__build__'),
filename: '[name].js',
publicPath: '/__build__/'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.css$/,
use: [
'style-loader', 'css-loader'
]
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: [{
loader: 'url-loader?limit=100000'
}]
}
]
},
resolve: {
extensions: ['.js'],
alias: genAlias()
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
}
function genAlias () {
const alias = {
'@vue/vue': path.resolve(__dirname, './packages/vue/dist/vue.esm-browser.js')
}
const runtimePackageNames = ['reactivity', 'runtime-core', 'runtime-dom']
runtimePackageNames.forEach((name) => {
alias[`@vue/${name}`] = path.resolve(__dirname, `./packages/${name}/dist/${name}.esm-bundler.js`)
})
const compilePackageNames = ['compiler-core', 'compiler-dom']
compilePackageNames.forEach((name) => {
alias[`@vue/${name}`] = path.resolve(__dirname, `./packages/${name}/dist/${name}.cjs.js`)
})
return alias
}