engine.webpack.js
2.71 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
let path = require('path')
let env = { NODE_ENV: '"production"' }
let ora = require('ora')
let rm = require('rimraf')
let chalk = require('chalk')
let webpack = require('webpack')
function assetsPath (_path) {
let assetsSubDirectory = '/engine-assets'
return path.posix.join(assetsSubDirectory, _path)
}
function resolve (dir) {
// console.log(path.join(__dirname, '..', '../../back-end/preview/public/be-static-luban-h5/engine'));
return path.join(__dirname, '..', dir)
}
const engineBuildOutputDir = resolve('../../back-end/h5-api/public/engine-assets')
process.env.NODE_ENV = 'production'
let spinner = ora('building for production...')
spinner.start()
let webpackConfig = {
mode: 'production',
entry: {
engine: './src/engine-entry.js'
},
// devtool: config.build.productionSourceMap ? '#source-map' : false,
devtool: '#source-map',
output: {
path: engineBuildOutputDir,
filename: '[name].js',
// publicPath: '/public-path',
library: 'Engine'
},
resolve: {
extensions: ['.js', '.vue', '.json']
},
externals: {
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
// enable CSS Modules
modules: true,
// customize generated class names
localIdentName: '[local]_[hash:base64:8]'
}
}
]
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': env
})
]
}
rm(engineBuildOutputDir, err => {
if (err) throw err
webpack(webpackConfig, function (err, stats) {
spinner.stop()
if (err) throw err
// process.stdout.write(
// stats.toString({
// colors: true,
// modules: true,
// children: true,
// chunks: true,
// chunkModules: true
// }) + '\n\n'
// )
console.log(chalk.cyan(' Build complete.\n'))
console.log(
chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
" Opening index.html over file:// won't work.\n"
)
)
})
})