80 lines
2.2 KiB
JavaScript
80 lines
2.2 KiB
JavaScript
|
|
let path = require('path');
|
|
let entry = require('./webpack.entry.js');
|
|
let htmlPlugins = require('./webpack.html.js');
|
|
const webpack = require('webpack');
|
|
var CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
|
|
// 根据环境选择变量
|
|
let outputPath = process.env.NODE_ENV === 'production' ? path.resolve('Z:/cdn/edp/js/') : path.resolve('./dist/');
|
|
let publicPath = process.env.NODE_ENV === 'production' ? '//cdn.dianwutong.com/edp/js' : '';
|
|
|
|
let config = {
|
|
context: __dirname,
|
|
entry: entry,
|
|
mode: 'none',
|
|
output: {
|
|
path: path.resolve('./dist/'),
|
|
publicPath: '', // 插入到html中的静态文件的路径前缀
|
|
filename: '[name].[hash].js'
|
|
},
|
|
// devtool: "source-map",
|
|
module: {
|
|
rules: [{
|
|
test: /\.js$/,
|
|
exclude: /(node_modules)/,
|
|
loader: 'babel-loader',
|
|
query: {
|
|
presets: ['es2015']
|
|
}
|
|
|
|
}, {
|
|
test: /\.(png|jpg|gif|ttf)$/,
|
|
exclude: /(node_modules)/,
|
|
use: [{
|
|
loader: 'url-loader?limit=1024&name=images/[name].[ext]?[hash]',
|
|
}]
|
|
},
|
|
{
|
|
test: /\.(htm|html)$/i,
|
|
exclude: /(node_modules)/,
|
|
loader: 'html-withimg-loader'
|
|
}
|
|
, {
|
|
test: /\.scss$/,
|
|
exclude: /(node_modules)/,
|
|
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),
|
|
optimization: {
|
|
minimize: false
|
|
}
|
|
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
config.devServer = {
|
|
inline: true,
|
|
historyApiFallback: true,
|
|
port: 8888,
|
|
host: 'terminal.dianwutong.com'
|
|
}
|
|
|
|
config.devtool = '#source-map';
|
|
} else {
|
|
config.plugins.push(new CleanWebpackPlugin(['dist']));
|
|
config.optimization.minimize = true;
|
|
}
|
|
|
|
module.exports = config; |