Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"scripts": {
"dev": "webpack-dev-server --hot --open",
"dist": "rm -rf public && NODE_ENV=production webpack --config webpack-dist.config.js --display-optimization-bailout",
"jbdist": "tnpm i && NODE_ENV=production webpack --config webpack-dist.config.js"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"badjs-report": "^1.3.2",
"classnames": "^2.2.5",
"core-js": "^2.4.1",
"mobx": "^3.1.16",
"mobx-react": "^4.2.2",
"normalize.css": "^7.0.0",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-router-dom": "^4.1.1",
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"css-loader": "^0.28.4",
"end-webpack-plugin": "^1.0.0",
"extract-text-webpack-plugin": "^2.1.2",
"file-loader": "^0.11.2",
"ncp": "^2.0.0",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"web-webpack-plugin": "^1.8.2",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.5.0"
}
}
/* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs');
const path = require('path');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const ModuleConcatenationPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const EndWebpackPlugin = require('end-webpack-plugin');
const ncp = require('ncp').ncp;
const { AutoWebPlugin } = require('web-webpack-plugin');
const { name } = require('./package.json');
const CND = {
js: `//7.url.cn/edu/${name}/`,
css: `//8.url.cn/edu/${name}/`,
img: `//9.url.cn/edu/${name}/`
};
const autoPlugin = new AutoWebPlugin('./src/pages/', {
template: (pageName) => {
let templatePath = path.resolve('./src/pages/', pageName, 'template.html');
if (fs.existsSync(templatePath)) {
return templatePath;
}
return './src/assets/template.html';
},
commonsChunk: {
name: 'common',
// 超过4个以上的页面都用到的公共模块就抽取到common里去
minChunks: 4,
},
// 所有的css文件都放在8.url.cn
stylePublicPath: CND.css,
});
module.exports = {
entry: autoPlugin.entry({
vendor: './src/assets/vendor',
}),
output: {
path: path.resolve(__dirname, `public/cdn/${name}`),
publicPath: CND.js,
filename: '[name]_[chunkhash].js',
},
resolve: {
// 加快搜索速度
modules: [path.resolve(__dirname, 'node_modules')],
// es tree-shaking
mainFields: ['jsnext:main', 'browser', 'main'],
// 加快编译速度
alias: {
moment: 'moment/min/moment.min.js',
},
extensions: ['.jsx', '.js'],
},
module: {
// 这些库都是不依赖其它库的库 不需要解析他们可以加快编译速度
noParse: /node_modules\/(moment|chart\.js)/,
rules: [
{
test: /\.jsx?$/,
// cacheDirectory 缓存babel编译结果加快重新编译速度
loader: 'babel-loader?cacheDirectory',
// 只命中src目录里的js文件,加快webpack搜索速度
include: path.resolve(__dirname, 'src')
},
{
test: /\.js$/,
// 加载 imui 里的 @require '.css'
loaders: ['comment-require-loader'],
include: path.resolve(__dirname, 'node_modules/imui')
},
{
test: /\.scss$/,
// 提取出css
loaders: ExtractTextPlugin.extract({
// 通过css加载的文件都放在9.url.cn
publicPath: CND.img,
fallback: 'style-loader',
// 压缩css
use: ['css-loader?minimize', 'sass-loader']
}),
include: path.resolve(__dirname, 'src')
},
{
test: /\.css$/,
// 提取出css
loaders: ExtractTextPlugin.extract({
// 通过css加载的文件都放在9.url.cn
publicPath: CND.img,
fallback: 'style-loader',
// 压缩css
use: ['css-loader?minimize'],
}),
},
{
test: /\.(gif|png|jpe?g|eot|woff|ttf|svg|pdf)$/,
loader: 'file-loader',
},
]
},
plugins: [
new DefinePlugin({
'process.env': {
// 'NODE_ENV': JSON.stringify('production')
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new UglifyJsPlugin({
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
compress: {
// 在UglifyJs删除没有用到的代码时不输出警告
warnings: false,
// 删除所有的 `console` 语句,可以兼容ie浏览器
drop_console: true,
// 内嵌定义了但是只用到一次的变量
collapse_vars: true,
// 提取出出现多次但是没有定义成变量去引用的静态值
reduce_vars: true,
}
}),
// webpack3 Scope Hoisting
new ModuleConcatenationPlugin(),
new ExtractTextPlugin({
filename: '[name]_[contenthash].css',
allChunks: true,
}),
autoPlugin,
// 所有页面都会用到的基础运行环境
new CommonsChunkPlugin({
name: 'vendor',
chunks: ['vendor', 'common']
}),
new EndWebpackPlugin(() => {
ncp('public/cdn', 'public/webserver');
// 微信公众号验证文件
ncp('src/assets/MP_verify_hm4fH3NBUiMW0hpo.txt', 'public/webserver');
})
],
};
const path = require('path');
const fs = require('fs');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const { AutoWebPlugin } = require('web-webpack-plugin');
const autoPlugin = new AutoWebPlugin('./src/pages/', {
template: (pageName) => {
let templatePath = path.resolve('./src/pages/', pageName, 'template.html');
if (fs.existsSync(templatePath)) {
return templatePath;
}
return './src/assets/template.html';
},
commonsChunk: {
name: 'common',
// 超过4个以上的页面都用到的公共模块就抽取到common里去
minChunks: 4,
},
});
module.exports = {
entry: autoPlugin.entry({
vendor: './src/assets/vendor',
}),
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',
},
// 支持 npm link
symlinks: true,
},
module: {
// 这些库都是不依赖其它库的库 不需要解析他们可以加快编译速度
noParse: /node_modules\/(moment|chart\.js)/,
rules: [
{
test: /\.js$/,
// cacheDirectory 缓存babel编译结果加快重新编译速度
loader: 'babel-loader?cacheDirectory',
// 只命中src目录里的js文件,加快webpack搜索速度
include: path.resolve(__dirname, 'src')
},
{
test: /\.js$/,
// 加载 imui 里的 // @require '.css'
loaders: ['comment-require-loader'],
include: [path.resolve(__dirname, 'node_modules/imui')]
},
{
test: /\.scss$/,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, 'src')
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
},
{
test: /\.(gif|png|jpe?g|eot|woff|ttf|svg|pdf)$/,
loader: 'file-loader',
},
]
},
plugins: [
new DefinePlugin({
'process.env': {
// 'NODE_ENV': JSON.stringify('development')
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
autoPlugin,
// 所有页面都会用到的基础运行环境
new CommonsChunkPlugin({
name: 'vendor',
chunks: ['vendor', 'common']
}),
],
devtool: 'source-map',
};
@zikkeung

This comment has been minimized.

Copy link

zikkeung commented Mar 22, 2017

package.json都没有给出来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.