62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
|
|
let path = require('path')
|
|
let entry = require('./webpack.entry.js')
|
|
let htmlPlugins = require('./webpack.html.js')
|
|
const webpack = require('webpack')
|
|
let ReleaseHandlePlugin = require('./releaseHandlePlugin')
|
|
|
|
// 根据环境选择变量
|
|
let outputPath = process.env.NODE_ENV === 'production' ? path.resolve('Z:/cdn/edp/js/') : path.resolve('./dist/')
|
|
let publicPath = process.env.NODE_ENV === 'production' ? '//cdn.saas.dianwutong.com/edp/js' : ''
|
|
|
|
let config = {
|
|
context: __dirname,
|
|
entry: entry,
|
|
output: {
|
|
path: path.resolve('./dist/'),
|
|
publicPath: '', // 插入到html中的静态文件的路径前缀
|
|
filename: '[name].[hash].js'
|
|
},
|
|
module: {
|
|
rules: [{
|
|
test: /\.js$/,
|
|
exclude: /(node_modules)/,
|
|
loader: 'babel-loader',
|
|
query: {
|
|
presets: ['es2015']
|
|
}
|
|
|
|
}, {
|
|
test: /\.scss$/,
|
|
use: [{
|
|
loader: "style-loader" // 将 JS 字符串生成为 style 节点
|
|
}, {
|
|
loader: "css-loader" // 将 CSS 转化成 CommonJS 模块
|
|
}, {
|
|
loader: "sass-loader" // 将 Sass 编译成 CSS
|
|
}]
|
|
}]
|
|
},
|
|
plugins: [
|
|
new webpack.ProvidePlugin({
|
|
Promise: 'es6-promise-promise'
|
|
})
|
|
].concat(htmlPlugins)
|
|
|
|
}
|
|
|
|
if (process.env.NODE_ENV == 'development') {
|
|
config.devServer = {
|
|
inline: true,
|
|
historyApiFallback: true,
|
|
port: 8020,
|
|
host: 'account.dianwutong.com'
|
|
}
|
|
} else if (process.env.NODE_ENV == 'test') {
|
|
config.plugins.push(new ReleaseHandlePlugin({ env: 'test' }))
|
|
} else if (process.env.NODE_ENV == 'production') {
|
|
config.plugins.push(new webpack.optimize.UglifyJsPlugin())
|
|
config.plugins.push(new ReleaseHandlePlugin({ env: 'production' }))
|
|
}
|
|
|
|
module.exports = config |