-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
73 lines (73 loc) · 2.12 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
73
const webpack = require('webpack');
const path = require('path');
const glob = require('glob');
const AssetsPlugin = require('assets-webpack-plugin');
const entryPath = 'src/pages';
const outputPath = 'public/dist';
const files = glob.sync(path.join(entryPath, '**/index.ts'));
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const entries = {};
for (let v of files) {
let dir = path.dirname(v.replace(entryPath + '/', ''));
entries[dir] = ['./src/global', './' + v];
}
module.exports = {
context: path.join(__dirname),
entry: entries,
output: {
path: path.resolve(__dirname, outputPath),
publicPath: 'http://localhost:8080/public/dist/',
filename: '[name]/index.js'
},
resolve: {
modules: [
path.resolve(__dirname, 'src/components'), path.resolve(__dirname, 'node_modules')
],
extensions: ['.js', '.ts']
},
module: {
rules: [{
test: /\.tsx?$/,
use: ['ts-loader']
},
{
test: /\.(png|jpg|gif|woff2|eot|woff|ttf|svg)$/,
use: [{
loader: 'url-loader',
options: { // 这里的 limit=8192 表示用 base64 编码 <= 8K 的图像
limit: 8192
}
}],
},
{
test: /\.css$/,
use: ['style-loader',
'css-loader'
]
},
{
test: /\.less$/,
use: ['style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer, cssnano]
}
},
'less-loader'
]
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common'
}),
new AssetsPlugin({
filename: 'assets.json'
})
],
devtool: 'source-map'
};