This repository was archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
132 lines (121 loc) · 3.61 KB
/
webpack.config.js
File metadata and controls
132 lines (121 loc) · 3.61 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const path = require('path'),
fs = require('fs'),
webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
CordovaHtmlOutputPlugin = require('./webpack/plugins/CordovaHtmlOutputPlugin.js'),
UglifyJsPlugin = require('webpack-uglify-js-plugin'),
CleanPlugin = require('clean-webpack-plugin'),
ExtractTextPlugin = require("extract-text-webpack-plugin"),
entryFile = path.join(__dirname, 'src/main.js'),
devServerPort = 8080
let config = function (env) {
let returner = {
entry: entryFile,
resolve: {
extensions: ['.js', '.json', '.vue'],
modules: [path.join(__dirname, 'src'), 'node_modules'],
alias: {
'vue$': 'vue/dist/vue.common.js',
'src': path.resolve(__dirname, 'src/'),
'assets': path.resolve(__dirname, 'src/assets/'),
'pages': path.resolve(__dirname, 'src/assets/vue/pages/'),
'components': path.resolve(__dirname, 'src/assets/vue/components/')
}
},
output: {
pathinfo: true,
devtoolLineToLine: true,
filename: '[hash].[name].js',
sourceMapFilename: "[hash].[name].js.map",
path: path.join(__dirname, 'www')
},
module: {
rules: [
{test: /\.js?$/, loader: 'source-map-loader', enforce: 'pre'},
{test: /\.(png|jpe?g|gif)$/, loader: 'file-loader', options: {name: '[name].[ext]?[hash]'}},
{test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'file-loader', options: {name: '[name].[ext]?[hash]'}},
{test: /\.svg$/, loader: 'url-loader'},
{test: /\.s[ca]ss$/, loader: ['style-loader', 'css-loader', 'sass-loader']},
{test: /\.vue$/, loader: 'vue-loader'}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify((env && typeof env != "undefined" && env.release) ? 'production' : 'development')
}
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.html',
inject: true,
minify: {
removeComments: true,
removeScriptTypeAttributes: true,
removeAttributeQuotes: true,
useShortDoctype: true,
decodeEntities: true,
collapseWhitespace: true,
minifyCSS: true
}
})
]
}
if (typeof env == "undefined" || typeof env.devserver == "undefined") {
returner.plugins.push(new CordovaHtmlOutputPlugin())
returner.plugins.push(new ExtractTextPlugin("styles.css"))
returner.module.rules.push({
test: /\.css$/, use: ExtractTextPlugin.extract({
fallbackLoader: "style-loader",
loader: "css-loader"
})
})
}
if (env) {
if (typeof env.devserver != 'undefined' && env.devserver) {
returner.module.rules.push({
test: /\.css$/, loader: ['style-loader', 'css-loader']
})
returner.entry = [
entryFile,
path.resolve(__dirname, "webpack/dev_helpers/CordovaDeviceRouter.js")
]
returner.output.publicPath = "/"
returner.devtool = "eval"
returner.devServer = {
contentBase: path.join(__dirname, "www"),
port: devServerPort,
stats: {colors: true},
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
headers: {
"Access-Control-Allow-Origin": "*"
},
host: "0.0.0.0"
}
returner.plugins.push(new webpack.NamedModulesPlugin())
} else if (typeof env.release != 'undefined' && env.release) {
returner.plugins.push(new CleanPlugin("www", {
root: path.join(__dirname, "."),
dry: false,
exclude: ["index.html"]
}))
returner.plugins.push(new UglifyJsPlugin({
cacheFolder: path.resolve(__dirname, 'webpack/cached_uglify/'),
debug: true,
minimize: true,
output: {
comments: false
},
compressor: {
warnings: false
}
}
))
}
}
return returner
}
module.exports = config