diff --git a/package.json b/package.json index 8c9f2495e..3b89c6b7f 100644 --- a/package.json +++ b/package.json @@ -74,11 +74,12 @@ }, "scripts": { "lint": "eslint src", - "build": "cross-env WEBPACK_ENV=prod && npm run lint && npm run test && npm run v:patch && webpack && npm run build:css", - "build-n": "cross-env WEBPACK_ENV=prod && npm run lint && npm run test && webpack && npm run build:css", + "build": "npm run lint && npm run test && npm run v:patch && webpack --env=dev && webpack --env=prod && npm run build:css", + "build-n": "npm run lint && npm run test && webpack --env=prod && npm run build:css", + "build-dev": "webpack --env=dev && npm run build:css", "build:css": "node-sass src/styles/scss/main.scss dist/css/grapes.min.css --output-style compressed", "v:patch": "npm version --no-git-tag-version patch", - "start": "cross-env WEBPACK_ENV=dev webpack-dev-server --progress --colors & npm run build:css -- -w", + "start": "cross-env WEBPACK_ENV=dev webpack-dev-server --env=dev --progress --colors & npm run build:css -- -w", "test": "cross-env NODE_PATH=./src mocha --compilers js:babel-core/register --require test/helper.js --timeout 10000 --recursive test/main.js", "test:dev": "npm test -- -R min -w" } diff --git a/webpack.config.js b/webpack.config.js index 0ea77c4af..807e8985e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,37 +2,43 @@ var HtmlWebpackPlugin = require('html-webpack-plugin'); var pkg = require('./package.json'); var webpack = require('webpack'); var fs = require('fs'); -var plugins = []; -if (process.env.WEBPACK_ENV !== 'dev') { - plugins = [ - new webpack.optimize.ModuleConcatenationPlugin(), - new webpack.optimize.UglifyJsPlugin({ minimize:true, compressor: {warnings:false}}), - new webpack.BannerPlugin(pkg.name + ' - ' + pkg.version), - ] -} else { - var index = 'index.html'; - var indexDev = '_' + index; - plugins.push(new HtmlWebpackPlugin({ - template: fs.existsSync(indexDev) ? indexDev : index - })); -} +module.exports = env => { + var plugins = []; + + var output = { + filename: './dist/grapes.min.js', + library: 'grapesjs', + libraryTarget: 'umd', + }; -plugins.push(new webpack.ProvidePlugin({ - _: 'underscore', - Backbone: 'backbone' -})); - -module.exports = { - entry: './src', - output: { - filename: './dist/grapes.min.js', - library: 'grapesjs', - libraryTarget: 'umd', - }, - plugins: plugins, - module: { - loaders: [{ + if (env.prod || env.production) { + plugins = [ + new webpack.optimize.ModuleConcatenationPlugin(), + new webpack.optimize.UglifyJsPlugin({ minimize:true, compressor: {warnings:false}}), + new webpack.BannerPlugin(pkg.name + ' - ' + pkg.version), + ]; + output.filename = './dist/grapes.min.js'; + } else { + var index = 'index.html'; + var indexDev = '_' + index; + plugins.push(new HtmlWebpackPlugin({ + template: fs.existsSync(indexDev) ? indexDev : index + })); + output.filename = './dist/grapes.js'; + } + + plugins.push(new webpack.ProvidePlugin({ + _: 'underscore', + Backbone: 'backbone' + })); + + return { + entry: './src', + output: output, + plugins: plugins, + module: { + loaders: [{ test: /grapesjs\/index\.js$/, loader: 'string-replace-loader', query: { @@ -44,12 +50,13 @@ module.exports = { loader: 'babel-loader', include: /src/, exclude: /node_modules/ - }], - }, - resolve: { - modules: ['src', 'node_modules'], - alias: { - jquery: 'cash-dom' + }], + }, + resolve: { + modules: ['src', 'node_modules'], + alias: { + jquery: 'cash-dom' + } } - }, + }; }