From a2fa97e3f5b9258dd44fe9fc04fe121bb39be92e Mon Sep 17 00:00:00 2001 From: squidfunk <martin.donath@squidfunk.com> Date: Sat, 3 Mar 2018 15:32:47 +0100 Subject: [PATCH] Fixed variable requires where possible in webpack config --- typings/css-mqpacker.d.ts | 23 +++++++++++++++++++++++ typings/index.d.ts | 26 ++++++++++++++++++++++++++ webpack.config.ts | 19 +++++++++++-------- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 typings/css-mqpacker.d.ts create mode 100644 typings/index.d.ts diff --git a/typings/css-mqpacker.d.ts b/typings/css-mqpacker.d.ts new file mode 100644 index 00000000..79e245b0 --- /dev/null +++ b/typings/css-mqpacker.d.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016-2018 Martin Donath <martin.donath@squidfunk.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +declare module "css-mqpacker" diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 00000000..aa341be0 --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016-2018 Martin Donath <martin.donath@squidfunk.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +declare module "*.json" { + const value: any + export default value +} diff --git a/webpack.config.ts b/webpack.config.ts index 2e3ee795..c219fe7a 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -20,11 +20,15 @@ * IN THE SOFTWARE. */ +import * as autoprefixer from "autoprefixer" +import * as mqpacker from "css-mqpacker" import * as fs from "fs" import * as html from "html-minifier" import * as path from "path" import * as uglify from "uglify-js" +import metadata from "./package.json" + import { Configuration, NewModule, @@ -162,7 +166,6 @@ export default (env?: { prod?: boolean }) => { context: "src", from: "**/*.html", transform: (content: string) => { - const metadata = require(path.resolve(__dirname, "package.json")) return html.minify(content.toString(), { collapseBooleanAttributes: true, includeAutoGeneratedTags: false, @@ -201,9 +204,9 @@ export default (env?: { prod?: boolean }) => { macOS when starting for the first time. This is a quick fix until this issue is resolved. See: http://bit.ly/2AsizEn */ new EventHooksPlugin({ - "watch-run": (compiler: any, cb: () => {}) => { + "watch-run": (compiler: any, done: () => {}) => { compiler.startTime += 10000 - cb() + done() }, "done": (stats: any) => { stats.startTime -= 10000 @@ -240,7 +243,7 @@ export default (env?: { prod?: boolean }) => { /* Register plugin */ config.plugins.push(plugin); (config.module as NewModule).rules.push({ - test: new RegExp(`${stylesheet}$`), + test: new RegExp(stylesheet), use: plugin.extract({ use: [ { @@ -255,8 +258,8 @@ export default (env?: { prod?: boolean }) => { options: { ident: "postcss", plugins: () => [ - require("autoprefixer")(), - require("css-mqpacker") + autoprefixer(), + mqpacker ], sourceMap: !(env && env.prod) } @@ -328,7 +331,7 @@ export default (env?: { prod?: boolean }) => { /* Apply manifest */ new EventHooksPlugin({ - "after-emit": (compilation: any, cb: () => {}) => { + "after-emit": (compilation: any, done: () => {}) => { const manifest = require(path.resolve("material/manifest.json")) Object.keys(compilation.assets).forEach(name => { if (name.match(/\.html/)) { @@ -339,7 +342,7 @@ export default (env?: { prod?: boolean }) => { fs.writeFileSync(asset.existsAt, replaced) } }) - cb() + done() } }) ) -- GitLab