Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
const path = require('path');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
let distConfig = require('./webpack.config');
distConfig.output.path = path.resolve(__dirname, 'public/cdn');
distConfig.output.publicPath = '//url.cn/';
distConfig.output.filename = '[chunkhash].js';
distConfig.resolve.alias = {
'moment': 'moment/min/moment.min.js',
'react': 'react/dist/react.min.js',
'react-dom': 'react-dom/dist/react-dom.min.js'
};
distConfig.plugins.push(...[
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new UglifyJsPlugin({
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
compress: {
// 在UglifyJs删除没有用到的代码时不输出警告
warnings: false,
// 删除所有的 `console` 语句,可以兼容ie浏览器
drop_console: true,
// 内嵌定义了但是只用到一次的变量
collapse_vars: true,
// 提取出出现多次但是没有定义成变量去引用的静态值
reduce_vars: true,
}
}),
])
module.exports = distConfig;
const fs = require('fs');
const path = require('path');
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
const AutoWebPlugin = require('web-webpack-plugin').AutoWebPlugin;
module.exports = {
output: {
publicPath: '',
filename: '[name].js',
},
resolve: {
// 加快搜索速度
modules: [path.resolve(__dirname, 'node_modules')],
// es tree-shaking
mainFields: ['jsnext:main', 'browser', 'main'],
// 加快编译速度
alias: {
'moment': 'moment/min/moment.min.js',
'react': 'react/dist/react.js',
'react-dom': 'react-dom/dist/react-dom.js'
}
},
module: {
// 这些库都是不依赖其它库的库 不需要解析他们可以加快编译速度
noParse: /node_modules\/(moment|chart\.js)/,
loaders: [
{
test: /\.js$/,
// cacheDirectory 缓存babel编译结果加快重新编译速度
loader: 'babel-loader?cacheDirectory',
// 只命中src目录里的js文件,加快webpack搜索速度
include: path.resolve(__dirname, 'src')
},
{
test: /\.scss$/,
// 压缩css
loaders: ['style-loader', 'css-loader?minimize', 'sass-loader'],
include: path.resolve(__dirname, 'src')
},
{
test: /\.css$/,
// 压缩css
loaders: ['style-loader', 'css-loader?minimize'],
},
{
test: /\.(gif|png|eot|woff|ttf|pdf)$/,
loader: 'file-loader',
},
]
},
performance: {
"hints": false
},
entry: {
badjs: './src/assets/badjs',
polyfill: './src/assets/polyfill',
ie_polyfill: './src/assets/ie-polyfill',
},
plugins: [
new AutoWebPlugin('./src/pages/', {
template: './src/assets/template.html',
commonsChunk: 'common'
}),
]
};

package.json都没有给出来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment