From 769f40e1178ee62b88d2aca0180f431b14a07ed5 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 24 Oct 2018 17:24:32 +0100 Subject: [PATCH] Updated configs --- package.json | 6 +- ....config.js => webpack.auto.dist.config.js} | 10 +- plugins/spine/webpack.canvas.config.js | 2 +- plugins/spine/webpack.canvas.dist.config.js | 94 +++++++++++++++++++ plugins/spine/webpack.webgl.config.js | 2 +- plugins/spine/webpack.webgl.dist.config.js | 94 +++++++++++++++++++ 6 files changed, 200 insertions(+), 8 deletions(-) rename plugins/spine/{webpack.dist.config.js => webpack.auto.dist.config.js} (88%) create mode 100644 plugins/spine/webpack.canvas.dist.config.js create mode 100644 plugins/spine/webpack.webgl.dist.config.js diff --git a/package.json b/package.json index 3c4ca67f7..fe9244d08 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,11 @@ "plugin.cam3d": "webpack --config plugins/camera3d/webpack.config.js", "plugin.spine": "webpack --config plugins/spine/webpack.config.js", "plugin.spine.dist": "webpack --config plugins/spine/webpack.auto.dist.config.js", - "plugin.spine.watch": "webpack --config plugins/spine/webpack.auto.config.js --watch", + "plugin.spine.watch": "webpack --config plugins/spine/webpack.auto.config.js --watch --display-modules", "plugin.spine.canvas.dist": "webpack --config plugins/spine/webpack.canvas.dist.config.js", - "plugin.spine.canvas.watch": "webpack --config plugins/spine/webpack.canvas.config.js --watch", + "plugin.spine.canvas.watch": "webpack --config plugins/spine/webpack.canvas.config.js --watch --display-modules", "plugin.spine.webgl.dist": "webpack --config plugins/spine/webpack.webgl.dist.config.js", - "plugin.spine.webgl.watch": "webpack --config plugins/spine/webpack.webgl.config.js --watch", + "plugin.spine.webgl.watch": "webpack --config plugins/spine/webpack.webgl.config.js --watch --display-modules", "lint": "eslint --config .eslintrc.json \"src/**/*.js\"", "lintfix": "eslint --config .eslintrc.json \"src/**/*.js\" --fix", "sloc": "node-sloc \"./src\" --include-extensions \"js\"", diff --git a/plugins/spine/webpack.dist.config.js b/plugins/spine/webpack.auto.dist.config.js similarity index 88% rename from plugins/spine/webpack.dist.config.js rename to plugins/spine/webpack.auto.dist.config.js index 2ef4ab500..ab9851722 100644 --- a/plugins/spine/webpack.dist.config.js +++ b/plugins/spine/webpack.auto.dist.config.js @@ -11,8 +11,8 @@ module.exports = { context: `${__dirname}/src/`, entry: { - 'SpinePlugin': './SpinePlugin.js', - 'SpinePlugin.min': './SpinePlugin.js' + 'SpinePlugin': './SpineWebGLPlugin.js', + 'SpinePlugin.min': './SpineWebGLPlugin.js' }, output: { @@ -52,7 +52,7 @@ module.exports = { resolve: { alias: { 'SpineCanvas': './runtimes/spine-canvas.js', - 'SpineGL': './runtimes/spine-webgl.js' + 'SpineWebGL': './runtimes/spine-webgl.js' }, }, @@ -75,6 +75,10 @@ module.exports = { }, plugins: [ + new webpack.DefinePlugin({ + "typeof CANVAS_RENDERER": JSON.stringify(true), + "typeof WEBGL_RENDERER": JSON.stringify(true) + }), new CleanWebpackPlugin([ 'dist' ]), { apply: (compiler) => { diff --git a/plugins/spine/webpack.canvas.config.js b/plugins/spine/webpack.canvas.config.js index 821c0871f..ead98a894 100644 --- a/plugins/spine/webpack.canvas.config.js +++ b/plugins/spine/webpack.canvas.config.js @@ -50,7 +50,7 @@ module.exports = { resolve: { alias: { 'SpineCanvas': './runtimes/spine-canvas.js', - 'SpineGL': './runtimes/spine-webgl.js' + 'SpineWebGL': './runtimes/spine-webgl.js' }, }, diff --git a/plugins/spine/webpack.canvas.dist.config.js b/plugins/spine/webpack.canvas.dist.config.js new file mode 100644 index 000000000..4e275c6f8 --- /dev/null +++ b/plugins/spine/webpack.canvas.dist.config.js @@ -0,0 +1,94 @@ +'use strict'; + +const webpack = require('webpack'); +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); +const CleanWebpackPlugin = require('clean-webpack-plugin'); +const exec = require('child_process').exec; + +module.exports = { + mode: 'production', + + context: `${__dirname}/src/`, + + entry: { + 'SpineCanvasPlugin': './SpineCanvasPlugin.js', + 'SpineCanvasPlugin.min': './SpineCanvasPlugin.js' + }, + + output: { + path: `${__dirname}/dist/`, + filename: '[name].js', + library: 'SpineCanvasPlugin', + libraryTarget: 'umd', + sourceMapFilename: '[file].map', + devtoolModuleFilenameTemplate: 'webpack:///[resource-path]', // string + devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]', // string + umdNamedDefine: true + }, + + performance: { hints: false }, + + module: { + rules: [ + { + test: require.resolve('./src/runtimes/spine-canvas.js'), + use: 'imports-loader?this=>window' + }, + { + test: require.resolve('./src/runtimes/spine-canvas.js'), + use: 'exports-loader?spine' + }, + { + test: require.resolve('./src/runtimes/spine-webgl.js'), + use: 'imports-loader?this=>window' + }, + { + test: require.resolve('./src/runtimes/spine-webgl.js'), + use: 'exports-loader?spine' + } + ] + }, + + resolve: { + alias: { + 'SpineCanvas': './runtimes/spine-canvas.js', + 'SpineWebGL': './runtimes/spine-webgl.js' + }, + }, + + optimization: { + minimizer: [ + new UglifyJSPlugin({ + include: /\.min\.js$/, + parallel: true, + sourceMap: false, + uglifyOptions: { + compress: true, + ie8: false, + ecma: 5, + output: {comments: false}, + warnings: false + }, + warningsFilter: () => false + }) + ] + }, + + plugins: [ + new webpack.DefinePlugin({ + "typeof CANVAS_RENDERER": JSON.stringify(true), + "typeof WEBGL_RENDERER": JSON.stringify(false) + }), + new CleanWebpackPlugin([ 'dist' ]), + { + apply: (compiler) => { + compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => { + exec('node plugins/spine/copy-to-examples.js', (err, stdout, stderr) => { + if (stdout) process.stdout.write(stdout); + if (stderr) process.stderr.write(stderr); + }); + }); + } + } + ] +}; diff --git a/plugins/spine/webpack.webgl.config.js b/plugins/spine/webpack.webgl.config.js index c341fca8a..22d66647e 100644 --- a/plugins/spine/webpack.webgl.config.js +++ b/plugins/spine/webpack.webgl.config.js @@ -50,7 +50,7 @@ module.exports = { resolve: { alias: { 'SpineCanvas': './runtimes/spine-canvas.js', - 'SpineGL': './runtimes/spine-webgl.js' + 'SpineWebGL': './runtimes/spine-webgl.js' }, }, diff --git a/plugins/spine/webpack.webgl.dist.config.js b/plugins/spine/webpack.webgl.dist.config.js new file mode 100644 index 000000000..35cf199e6 --- /dev/null +++ b/plugins/spine/webpack.webgl.dist.config.js @@ -0,0 +1,94 @@ +'use strict'; + +const webpack = require('webpack'); +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); +const CleanWebpackPlugin = require('clean-webpack-plugin'); +const exec = require('child_process').exec; + +module.exports = { + mode: 'production', + + context: `${__dirname}/src/`, + + entry: { + 'SpineWebGLPlugin': './SpineWebGLPlugin.js', + 'SpineWebGLPlugin.min': './SpineWebGLPlugin.js' + }, + + output: { + path: `${__dirname}/dist/`, + filename: '[name].js', + library: 'SpineWebGLPlugin', + libraryTarget: 'umd', + sourceMapFilename: '[file].map', + devtoolModuleFilenameTemplate: 'webpack:///[resource-path]', // string + devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]', // string + umdNamedDefine: true + }, + + performance: { hints: false }, + + module: { + rules: [ + { + test: require.resolve('./src/runtimes/spine-canvas.js'), + use: 'imports-loader?this=>window' + }, + { + test: require.resolve('./src/runtimes/spine-canvas.js'), + use: 'exports-loader?spine' + }, + { + test: require.resolve('./src/runtimes/spine-webgl.js'), + use: 'imports-loader?this=>window' + }, + { + test: require.resolve('./src/runtimes/spine-webgl.js'), + use: 'exports-loader?spine' + } + ] + }, + + resolve: { + alias: { + 'SpineCanvas': './runtimes/spine-canvas.js', + 'SpineWebGL': './runtimes/spine-webgl.js' + }, + }, + + optimization: { + minimizer: [ + new UglifyJSPlugin({ + include: /\.min\.js$/, + parallel: true, + sourceMap: false, + uglifyOptions: { + compress: true, + ie8: false, + ecma: 5, + output: {comments: false}, + warnings: false + }, + warningsFilter: () => false + }) + ] + }, + + plugins: [ + new webpack.DefinePlugin({ + "typeof CANVAS_RENDERER": JSON.stringify(false), + "typeof WEBGL_RENDERER": JSON.stringify(true) + }), + new CleanWebpackPlugin([ 'dist' ]), + { + apply: (compiler) => { + compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => { + exec('node plugins/spine/copy-to-examples.js', (err, stdout, stderr) => { + if (stdout) process.stdout.write(stdout); + if (stderr) process.stderr.write(stderr); + }); + }); + } + } + ] +};