From fc9fb14498cf466083ba84c9d769dfd4cf296a83 Mon Sep 17 00:00:00 2001 From: marudor Date: Mon, 10 Sep 2018 19:53:19 +0200 Subject: [PATCH] Asset step & script --- package.json | 8 +++++++- scripts/copyAssets.js | 25 +++++++++++++++++++++++++ webpack.config.js | 7 ------- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 scripts/copyAssets.js diff --git a/package.json b/package.json index ddd8ef8b..d671bda6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "author": "marudor ", "license": "MIT", "scripts": { - "build": "NODE_ENV=production webpack", + "build": "npm run -s build:clean && NODE_ENV=production run-p build:assets build:webpack", + "build:clean": "rimraf public/assets", + "build:assets": "node scripts/copyAssets.js", + "build:webpack": "webpack", "build:watch": "webpack --watch" }, "dependencies": { @@ -29,6 +32,9 @@ "imports-loader": "^0.8.0", "less": "^3.0.2", "less-loader": "^4.0.5", + "mkdirp": "^0.5.1", + "npm-run-all": "^4.1.3", + "rimraf": "^2.6.2", "style-loader": "^0.21.0", "webpack": "^3" } diff --git a/scripts/copyAssets.js b/scripts/copyAssets.js new file mode 100644 index 00000000..3c425baa --- /dev/null +++ b/scripts/copyAssets.js @@ -0,0 +1,25 @@ +const fs = require("fs"); +const path = require("path"); +const mkdirp = require("mkdirp"); + +const baseAssetPath = { + src: path.resolve("resources/assets"), + target: path.resolve("public/assets") +}; + +const emojiPath = { + src: baseAssetPath.src + "/emojis", + target: baseAssetPath.target + "/emojis" +}; + +mkdirp.sync(emojiPath.target); + +const emojis = fs.readdirSync(emojiPath.src); + +emojis.forEach(e => { + fs.copyFile(`${emojiPath.src}/${e}`, `${emojiPath.target}/${e}`, e => { + if (e) { + console.error(e); + } + }); +}); diff --git a/webpack.config.js b/webpack.config.js index fd36b0f9..261c1c44 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,11 +23,6 @@ for (let i = 0; i < 7; i++) { themeEntries[`theme${i}`] = `./resources/assets/themes/theme${i}.less`; } -const emojis = {}; -for (let emoji of ['redface', 'wind', 'smile', 'sad', 'lol', 'cry', 'rolleyes', 'evil', 'mad', 'question']){ - emojis[`${emoji}`] = `./resources/assets/emojis/${emoji}.gif`; -} - module.exports = { context: __dirname, resolve: { @@ -36,7 +31,6 @@ module.exports = { entry: { ...themeEntries, vendor: './resources/assets/js/vendor.js', - ...emojis, }, output: { path: path.resolve('public/assets'), @@ -52,7 +46,6 @@ module.exports = { query: { cacheDirectory: true }, }, { test: /\.(eot|ttf|otf|svg|woff2?)(\?.*)?$/, loader: 'file-loader' }, - { test: /\.gif$/, loader: 'file-loader?name=emojis/[name].[ext]' }, { test: /\.json$/, loader: 'json-loader' }, { test: /\.css$/, loader: 'style-loader!css-loader' }, { test: /\.less$/, use: ExtractTextPlugin.extract({