forked from xuqiang521/xuejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (89 loc) · 2.32 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const path = require('path')
const webpack = require('webpack')
const OpenBrowserWebpackPlugin = require('open-browser-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const port = process.env.NODE_ENV || 9000;
const uri = "http://localhost:" + port;
const ExtractLess = new ExtractTextPlugin({
filename: 'theme/[name].css'
})
module.exports = {
entry: {
xue: './src/modules/global-api.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'scripts/[name].js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['es2015']
}
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
attrs: ['img:src', 'link:href']
}
},
{
test: /\.less$/,
exclude: /node_modules/,
// loader: 'style-loader!css-loader!less-loader',
loader: ExtractLess.extract(
{
fallback:'style-loader',
use: [
'css-loader',
'less-loader',
{
loader: 'postcss-loader',
options: {
plugins: [require('autoprefixer')]
}
}
]
})
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
loader: 'url-loader'
}
]
},
plugins: [
new OpenBrowserWebpackPlugin({
url: uri
}),
new HtmlWebpackPlugin({
// filename: 'pages/index.html',
template: './src/pages/index.html'
}),
// 生成独立css文件
ExtractLess
// new webpack.HotModuleReplacementPlugin()
],
resolve: {
extensions: ['.js', '.json', '.css', '.less'],
alias: {
'utils': path.resolve(__dirname, 'src/modules/utils'),
'compiler': path.resolve(__dirname, 'src/modules/compiler'),
'watcher': path.resolve(__dirname, 'src/modules/watcher'),
'observer': path.resolve(__dirname, 'src/modules/observer'),
'styles': path.resolve(__dirname, 'src/views')
}
},
devServer: {
// contentBase: path.resolve(__dirname, 'src'),
// hot: true,
port: port,
historyApiFallback: true
}
}