-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
105 lines (101 loc) · 3.17 KB
/
webpack.config.js
File metadata and controls
105 lines (101 loc) · 3.17 KB
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
95
96
97
98
99
100
101
102
103
104
105
const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const version = process.env.npm_package_version || '-development';
const config = {
context: path.resolve(__dirname, 'src'),
entry: {
app: ['@/index.js'],
vendor: [
'font-awesome-webpack',
'materialize-css',
'materialize-css/dist/css/materialize.min.css',
'jquery',
'underscore',
'vue',
'vue-router',
],
},
output: {
filename: '[name].bundle.' + version + '.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [{ // .vue loader including scss and sass
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
'scss': 'vue-style-loader!css-loader!sass-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
}
}
}, { // basic js loaders
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
'eslint-loader',
]
}, { // used for materialize fonts
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: './fonts/[hash].[ext]',
mimetype: 'application/font-woff'
}
}, { // used for materialize fonts
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
options: {
name: './fonts/[hash].[ext]',
}
}, { // load css
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery',
'_': 'underscore',
'window._': 'underscore',
}),
// add version number to html file
new CopyWebpackPlugin([{
from: '../static',
to: '.',
transform: function (content) {
const str = content.toString();
return str.replace(/(src="[^"]*)(\.js")/g, '$1.' + version + '$2');
}
}])
],
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': path.resolve(__dirname, 'src')
}
}
};
if (process.env.NODE_ENV === 'production') {
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// use this to hot replace NODE_ENV in vuejs source
config.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}));
config.plugins.push(new CleanWebpackPlugin(['dist']));
config.plugins.push(new UglifyJsPlugin());
}
module.exports = config;