128 lines
4.0 KiB
JavaScript
128 lines
4.0 KiB
JavaScript
let fs = require('fs')
|
||
let path = require('path')
|
||
let entry = require('./webpack.entry.js')
|
||
let htmlPlugins = require('./webpack.html.js')
|
||
const webpack = require('webpack')
|
||
let ReleaseHandlePlugin = require('./releaseHandlePlugin')
|
||
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||
var CleanWebpackPlugin = require('clean-webpack-plugin')
|
||
// let px2rem = require('postcss-px2rem');
|
||
// 根据环境选择变量
|
||
|
||
let config = {
|
||
context: __dirname,
|
||
entry: entry,
|
||
devtool: 'source-map',
|
||
watchOptions: {
|
||
//不监听的node_modules目录下的文件,
|
||
ignored: /node_modules/,
|
||
//监听到变化发生后会等300ms再去执行动作,防止文件更新太快
|
||
//默认为300ms
|
||
aggregateTimeout: 300,
|
||
//判断文件是否发生变化是通过不停询问系统指定文件有没有变化实现的
|
||
//默认每秒问1000次
|
||
poll: 1000
|
||
},
|
||
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$/,
|
||
exclude: /data-board.scss/,
|
||
use: ExtractTextPlugin.extract({
|
||
fallback: 'style-loader',
|
||
use: [
|
||
{
|
||
loader: 'css-loader',
|
||
options: {
|
||
minimize: true, //css压缩
|
||
}
|
||
},
|
||
{
|
||
loader: 'sass-loader',
|
||
options: {
|
||
minimize: true //css压缩
|
||
}
|
||
},
|
||
|
||
]
|
||
})
|
||
},
|
||
{
|
||
test: /data-board.scss/,
|
||
use: ExtractTextPlugin.extract({
|
||
fallback: 'style-loader',
|
||
use: [
|
||
{
|
||
loader: 'css-loader',
|
||
options: {
|
||
minimize: true, //css压缩
|
||
}
|
||
},
|
||
{
|
||
loader: 'px2rem-loader',
|
||
options: {
|
||
remUnit: 192,
|
||
},
|
||
},
|
||
{
|
||
loader: 'sass-loader',
|
||
options: {
|
||
minimize: true //css压缩
|
||
}
|
||
},
|
||
|
||
]
|
||
})
|
||
}
|
||
]
|
||
},
|
||
plugins: [
|
||
new webpack.ProvidePlugin({
|
||
Promise: 'es6-promise-promise'
|
||
}),
|
||
new ExtractTextPlugin('[name].css')
|
||
].concat(htmlPlugins)
|
||
|
||
}
|
||
|
||
if (process.env.NODE_ENV == 'development') {
|
||
config.devServer = {
|
||
inline: true,
|
||
historyApiFallback: true,
|
||
port: 8082,
|
||
https: {
|
||
key: fs.readFileSync(path.resolve(__dirname, "./https/9624814__saas.dianwutong.com.key")),
|
||
cert: fs.readFileSync(path.resolve(__dirname, "./https/9624814__saas.dianwutong.com.pem")),
|
||
},
|
||
host: 'edp.dianwutong.com'
|
||
}
|
||
config.plugins.push(new webpack.DllReferencePlugin({
|
||
context: __dirname,
|
||
manifest: require('./build/dev/vendor-manifest.json')
|
||
}))
|
||
|
||
config.devtool = '#source-map'
|
||
|
||
} else if (process.env.NODE_ENV == 'test') {
|
||
config.plugins.push(new CleanWebpackPlugin(['dist']))
|
||
config.plugins.push(new ReleaseHandlePlugin({ env: 'test' }))
|
||
config.plugins.push(new webpack.optimize.UglifyJsPlugin())
|
||
} else if (process.env.NODE_ENV == 'production') {
|
||
config.plugins.push(new CleanWebpackPlugin(['dist']))
|
||
config.plugins.push(new ReleaseHandlePlugin({ env: 'production' }))
|
||
config.plugins.push(new webpack.optimize.UglifyJsPlugin())
|
||
}
|
||
|
||
module.exports = config |