UNPKG

@nurun-sf/spark-component

Version:

A tool for building spark components

108 lines (93 loc) 2.47 kB
'use strict'; const path = require('path'); const webpack = require('webpack'); const getClassName = require('./get-class-name'); const getExternalDeps = require('./get-external-deps'); const brand = require('./brand'); const pkg = require(path.join(process.cwd(), 'package.json')); const DIST = 'dist'; const COMPONENT_NAME = pkg.name; const SOURCE = COMPONENT_NAME + '.js'; const PACKED = COMPONENT_NAME + '.packed.js'; const PACKED_MIN = COMPONENT_NAME + '.packed.min.js'; const INSTRUMENTED = COMPONENT_NAME + '.instrumented.js'; const EXTERNAL_DEPS = getExternalDeps(); const CLASS_NAME = getClassName(COMPONENT_NAME); const BOWER_DIR = path.join(process.cwd(), 'bower_components'); const BABEL_CONFIG = { presets: ['es2015'], plugins: [ ['transform-es2015-classes', { loose: true }], ['transform-proto-to-assign'], ], }; const BABEL_LOADER = { test: /\.js$/, exclude: /(node_modules|bower_components)/, loader: 'babel-loader', query: BABEL_CONFIG, }; const UGLIFY_CONFIG = { comments: false, screw_ie8: true, compress: { drop_console: true, }, mangle: true, }; var config = { isProduction: false, watch: false, babel: BABEL_CONFIG, dependencies: EXTERNAL_DEPS, className: CLASS_NAME, dist: DIST, filename: { source: SOURCE, dist: PACKED, min: PACKED_MIN, instrumented: INSTRUMENTED, }, library: brand, webpack: { name: 'build', devtool: 'source-map', entry: './' + SOURCE, output: { filename: PACKED, path: DIST, library: CLASS_NAME, libraryTarget: 'umd', }, externals: EXTERNAL_DEPS, resolve: { root: [BOWER_DIR] }, module: { loaders: [BABEL_LOADER] }, plugins: [ new webpack.ResolverPlugin( new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('.bower.json', ['main']) ), ], }, webpackMin: { name: 'minified', devtool: 'source-map', entry: './' + SOURCE, output: { filename: PACKED_MIN, path: DIST, library: CLASS_NAME, libraryTarget: 'umd', }, externals: EXTERNAL_DEPS, resolve: { root: [BOWER_DIR] }, module: { loaders: [BABEL_LOADER] }, plugins: [ new webpack.ResolverPlugin( new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('.bower.json', ['main']) ), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin(UGLIFY_CONFIG), ], }, }; module.exports = config;