0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

refactor: move webpack to root folder and rewrite to es6 node style (legacy compatibility)

This commit is contained in:
Juan Picado @jotadeveloper 2017-07-15 21:58:05 +02:00
parent 6be3c6841c
commit f8a7483b08
No known key found for this signature in database
GPG key ID: 18AC54485952D158
6 changed files with 42 additions and 37 deletions

View file

@ -45,7 +45,8 @@
"pkginfo": "^0.4.0", "pkginfo": "^0.4.0",
"request": "^2.72.0", "request": "^2.72.0",
"semver": "^5.1.0", "semver": "^5.1.0",
"unix-crypt-td-js": "^1.0.0" "unix-crypt-td-js": "^1.0.0",
"webpack-merge": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"axios": "0.16.2", "axios": "0.16.2",
@ -125,8 +126,8 @@
"lint": "eslint .", "lint": "eslint .",
"lint:css": "stylelint 'src/**/*.scss' --syntax scss", "lint:css": "stylelint 'src/**/*.scss' --syntax scss",
"build-docker": "docker build -t verdaccio .", "build-docker": "docker build -t verdaccio .",
"build:webui": "rimraf static/* && webpack --config src/webui/scripts/webpack.prod.config.babel.js", "build:webui": "rimraf static/* && webpack --config tools/webpack.prod.config.babel.js --debug",
"dev:webui": "babel-node src/webui/scripts/dev.server.js", "dev:webui": "babel-node tools/dev.server.js",
"prepublish": "in-publish && npm run build:webpack || not-in-publish", "prepublish": "in-publish && npm run build:webpack || not-in-publish",
"build-docker:rpi": "docker build -f Dockerfile.rpi -t verdaccio:rpi ." "build-docker:rpi": "docker build -f Dockerfile.rpi -t verdaccio:rpi ."
}, },

View file

@ -2,7 +2,7 @@ import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server'; import WebpackDevServer from 'webpack-dev-server';
import config from './webpack.dev.config.babel'; import config from './webpack.dev.config.babel';
import ora from 'ora'; import ora from 'ora';
import env from '../../config/env'; import env from '../src/config/env';
const compiler = webpack(config); const compiler = webpack(config);
const spinner = ora('Compiler is running...').start(); const spinner = ora('Compiler is running...').start();

View file

@ -1,17 +1,17 @@
import env from '../../config/env'; const env = require('../src/config/env');
const isDev = process.env.NODE_ENV === 'development'; const isDev = process.env.NODE_ENV === 'development';
export default { module.exports = {
entry: `${env.SRC_ROOT}/webui/src/index.js`, entry: `${env.SRC_ROOT}/webui/src/index.js`,
output: { output: {
path: `${env.APP_ROOT}/static/`, path: `${env.APP_ROOT}/static/`,
filename: '[name].[hash].js' filename: '[name].[hash].js',
}, },
resolve: { resolve: {
extensions: ['.js', '.jsx'] extensions: ['.js', '.jsx'],
}, },
module: { module: {
@ -19,14 +19,14 @@ export default {
/* Pre loader */ /* Pre loader */
{ {
enforce: 'pre', enforce: 'pre',
test: /\.jsx?$/, test: /\.js?$/,
exclude: /node_modules/, exclude: /node_modules/,
use: 'eslint-loader' use: 'eslint-loader'
}, },
/* Normal loader */ /* Normal loader */
{ {
test: /\.jsx?$/, test: /\.js?$/,
exclude: /node_modules/, exclude: /node_modules/,
use: 'babel-loader' use: 'babel-loader'
}, },
@ -78,5 +78,7 @@ export default {
devtool: isDev ? 'source-map' : 'eval', devtool: isDev ? 'source-map' : 'eval',
stats: {children: false} stats: {
children: false
}
}; };

View file

@ -2,7 +2,7 @@ import webpack from 'webpack';
import HTMLWebpackPlugin from 'html-webpack-plugin'; import HTMLWebpackPlugin from 'html-webpack-plugin';
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin'; import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
import baseConfig from './webpack.config'; import baseConfig from './webpack.config';
import env from '../../config/env'; import env from '../src/config/env';
export default { export default {
...baseConfig, ...baseConfig,

View file

@ -1,40 +1,30 @@
import webpack from 'webpack'; const webpack = require('webpack');
import HTMLWebpackPlugin from 'html-webpack-plugin'; const HTMLWebpackPlugin = require('html-webpack-plugin');
import ExtractTextPlugin from 'extract-text-webpack-plugin'; const ExtractTextPlugin = require('extract-text-webpack-plugin');
import baseConfig from './webpack.config'; const baseConfig = require('./webpack.config');
import env from '../../config/env'; const env = require('../src/config/env');
import _ from 'lodash'; const _ = require('lodash');
const merge = require('webpack-merge');
baseConfig.module.rules const prodConf = {
.filter((loader) =>
Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
).forEach((loader) => {
loader.use = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: _.tail(loader.use)
});
});
export default {
...baseConfig,
entry: { entry: {
main: `${env.SRC_ROOT}/webui/src/index.js` main: `${env.SRC_ROOT}/webui/src/index.js`,
}, },
output: { module: {
...baseConfig.output rules: [],
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'__DEBUG__': false, '__DEBUG__': false,
'process.env.NODE_ENV': '"production"' 'process.env.NODE_ENV': '"production"',
}), }),
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
sourceMap: true, sourceMap: true,
compress: { compress: {
warnings: false warnings: false
} },
}), }),
new ExtractTextPlugin('style.[contenthash].css'), new ExtractTextPlugin('style.[contenthash].css'),
new HTMLWebpackPlugin({ new HTMLWebpackPlugin({
@ -45,6 +35,18 @@ export default {
debug: false, debug: false,
inject: true, inject: true,
}), }),
new webpack.NoEmitOnErrorsPlugin() new webpack.NoEmitOnErrorsPlugin(),
] ],
}; };
prodConf.module.rules = baseConfig.module.rules
.filter((loader) =>
Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
).forEach((loader) => {
loader.use = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: _.tail(loader.use),
});
});
module.exports = merge(baseConfig, prodConf);