Authored by 沈志敏

webpack2

... ... @@ -8,11 +8,10 @@
"url": "http://git.dev.yoho.cn/web/yohobuywap-node.git"
},
"scripts": {
"start": "node app.js",
"start": "NODE_ENV=\"production\" node app.js",
"dev": "nodemon -e js,hbs -i public/ app.js",
"static": "webpack-dev-server --config ./public/build/webpack.dev.config.js",
"build": "webpack --config ./public/build/webpack.base.config.js",
"online": "NODE_ENV=\"production\" node app.js",
"build": "webpack --config ./public/build/webpack.prod.config.js",
"debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js",
"lint-js": "eslint -c .eslintrc --cache .",
"lint-css": "stylelint --syntax scss --config .stylelintrc public/scss/**/*.css",
... ... @@ -60,21 +59,15 @@
"babel-loader": "^6.4.1",
"babel-preset-env": "^1.2.2",
"css-loader": "^0.26.1",
"cssnano": "^3.10.0",
"eslint": "^3.16.0",
"eslint-config-yoho": "^1.0.1",
"eslint-plugin-html": "^2.0.1",
"extract-text-webpack-plugin": "^2.1.0",
"gulp": "^3.9.1",
"gulp-cssnano": "^2.1.2",
"gulp-ftp": "^1.1.0",
"gulp-postcss": "^6.3.0",
"gulp-sourcemaps": "^2.4.1",
"gulp-util": "^3.0.8",
"handlebars-loader": "^1.4.0",
"husky": "^0.13.1",
"nodemon": "^1.11.0",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.4",
"postcss-calc": "^5.3.1",
"postcss-center": "^1.0.0",
"postcss-clearfix": "^1.0.0",
... ... @@ -98,6 +91,7 @@
"vue-template-compiler": "^2.1.10",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.2",
"webpack-uglify-parallel": "^0.1.3",
"yoho-cookie": "^1.2.0",
"yoho-fastclick": "^1.0.6",
"yoho-hammer": "^2.0.7",
... ...
... ... @@ -2,7 +2,14 @@
* postcss plugins for both dev and pro
* @parem et Symbol
*/
const psprites = require('postcss-sprites');
const path = require('path');
const config = require('../../package.json');
const distDir = path.join(__dirname, `../dist/${config.name}/${config.version}`);
const dist = {
img: distDir + '/img',
font: distDir + '/font'
}
exports.postcssPlugin = (et) => {
let sprites = {
... ... @@ -26,8 +33,13 @@ exports.postcssPlugin = (et) => {
if (group) {
group = entry + '.' + group;
}
return group ? Promise.resolve(group) : Promise.reject('yoho');
},
hooks: {
onUpdateRule:function(rule, comment, image){
image.spriteUrl += ("?t=" + new Date().getTime());
psprites.updateRule(rule, comment, image);
}
}
},
assets,
... ... @@ -37,12 +49,13 @@ exports.postcssPlugin = (et) => {
if (et === 'pro') {
assets = {
loadPaths: [dist.img, dist.font],
relativeTo: dist.css
relativeTo: distDir,
cachebuster: true
};
Object.assign(sprites, {
basePath: dist.img,
stylesheetPath: dist.css,
stylesheetPath: distDir,
spritePath: dist.img
});
} else if (et === 'dev') {
... ... @@ -71,7 +84,7 @@ exports.postcssPlugin = (et) => {
}
}),
require('precss'),
require('postcss-sprites').default(sprites),
psprites.default(sprites),
require('postcss-assets')(assets),
require('postcss-calc'),
require('postcss-pxtorem')({
... ... @@ -92,9 +105,8 @@ exports.postcssPlugin = (et) => {
];
if (et === 'pro') {
plugins.push(require('postcss-cachebuster')({
imagesPath: `/${dist.img}`,
cssPath: `/${dist.css}`
plugins.push(require('cssnano')({
safe: true
}));
}
return plugins;
... ...
... ... @@ -32,91 +32,93 @@ shelljs.ls(path.join(__dirname, '../js/**/*.page.js')).forEach((f) => {
];
});
module.exports = {
entry: entries,
output: {
path: path.join(__dirname, 'bundle'), // absolute path
filename: '[name].js'
},
module: {
rules: [{
test: /\.vue$/,
use: [{
loader: 'vue-loader',
options: {
postcss: {
plugins: postcssConfig.postcssPlugin('dev'),
parser: scss
},
autoprefixer: false,
loaders: {
css: ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: [{
loader: 'css-loader',
options: {
url: false
}
}]
})
}
}
}],
}, {
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
module.exports = (env) => {
return {
entry: entries,
output: {
path: path.join(__dirname, 'bundle'), // absolute path
filename: '[name].js'
},
module: {
rules: [{
test: /\.vue$/,
use: [{
loader: 'css-loader',
loader: 'vue-loader',
options: {
url: false
postcss: {
plugins: postcssConfig.postcssPlugin(env),
parser: scss
},
autoprefixer: false,
loaders: {
css: ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: [{
loader: 'css-loader',
options: {
url: false
}
}]
})
}
}
}, {
loader: 'postcss-loader',
}],
}, {
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
url: false
}
}, {
loader: 'postcss-loader',
options: {
plugins: postcssConfig.postcssPlugin(env),
parser: scss
}
}],
})
}, {
test: /\.hbs$/,
use: [{
loader: 'handlebars-loader',
options: {
plugins: postcssConfig.postcssPlugin('dev'),
parser: scss
helperDirs: [
path.join(__dirname, '../js/common/helpers')
],
partialDirs: [
path.join(__dirname, '../../doraemon/views/partial')
]
}
}],
})
}, {
test: /\.hbs$/,
use: [{
loader: 'handlebars-loader',
options: {
helperDirs: [
path.join(__dirname, '../js/common/helpers')
],
partialDirs: [
path.join(__dirname, '../../doraemon/views/partial')
]
}
}]
}]
}]
},
resolve: {
modules: ['node_modules', './public/vue', './public/hbs', './public/scss', './public/js'],
alias: {
js: path.join(__dirname, '../js/'),
vue: 'vue/dist/vue.js'
}
},
plugins: [
new ExtractTextPlugin('[name].css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'libs',
filename: 'libs.js'
}),
new webpack.ProvidePlugin({
$: 'yoho-jquery',
jQuery: 'yoho-jquery',
'window.jQuery': 'yoho-jquery'
})
]
};
},
resolve: {
modules: ['node_modules', './public/vue', './public/hbs', './public/scss', './public/js'],
alias: {
js: path.join(__dirname, '../js/'),
vue: 'vue/dist/vue.js'
}
},
plugins: [
new ExtractTextPlugin('[name].css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'libs',
filename: 'libs.js'
}),
new webpack.ProvidePlugin({
$: 'yoho-jquery',
jQuery: 'yoho-jquery',
'window.jQuery': 'yoho-jquery'
})
]
}
};
\ No newline at end of file
... ...
const path = require('path');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const baseConfig = require('./webpack.base.config.js');
let baseConfig = require('./webpack.base.config.js');
baseConfig = baseConfig('dev');
baseConfig.devtool = '#inline-source-map';
baseConfig.output.publicPath = 'http://localhost:5001/';
baseConfig.devServer = {
... ...
const path = require('path');
const os = require('os');
const shelljs = require('shelljs');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const UglifyJsParallelPlugin = require('webpack-uglify-parallel');
const config = require('../../package.json');
const distDir = path.join(__dirname, `../dist/${config.name}/${config.version}`);
let baseConfig = require('./webpack.base.config.js');
// cope img font
shelljs.mkdir('-p', distDir);
shelljs.cp('-R', path.join(__dirname,'../img/'), distDir);
shelljs.cp('-R', path.join(__dirname,'../font/'), distDir);
baseConfig = baseConfig('pro');
baseConfig.output.path = distDir;
baseConfig.plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new UglifyJsParallelPlugin({
workers: os.cpus().length
})
);
module.exports = baseConfig;
\ No newline at end of file
... ...