Skip to content

Commit 3d1035a

Browse files
committed
using rollup to build project
1 parent cc3256f commit 3d1035a

File tree

8 files changed

+316
-80
lines changed

8 files changed

+316
-80
lines changed

build/index.js

-46
This file was deleted.

build/index.js.map

-1
This file was deleted.
+23-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { Compiler } from 'webpack';
2-
interface Module {
3-
type?: string;
4-
content: string;
5-
}
6-
interface Compilation {
7-
modules: Module[];
8-
}
9-
interface PluginData {
10-
html: string;
11-
assets: {
12-
css: string[];
13-
};
14-
}
15-
export default class Plugin {
16-
static makeReg(fileName: string): RegExp;
17-
static getStyleString(modules: Module[]): string;
18-
static addStyleInToHTML(compilation: Compilation, pluginData: PluginData): void;
19-
static removeLinkTag(pluginData: PluginData): void;
20-
static replace(compilation: Compilation, pluginData: PluginData, callback: (...args: any[]) => void): void;
21-
apply(compiler: Compiler): void;
22-
}
23-
export {};
1+
import { Compiler } from 'webpack';
2+
interface Module {
3+
type?: string;
4+
content: string;
5+
}
6+
interface Compilation {
7+
modules: Module[];
8+
}
9+
interface PluginData {
10+
html: string;
11+
assets: {
12+
css: string[];
13+
};
14+
}
15+
export default class Plugin {
16+
static makeReg(fileName: string): RegExp;
17+
static getStyleString(modules: Module[]): string;
18+
static addStyleInToHTML(compilation: Compilation, pluginData: PluginData): void;
19+
static removeLinkTag(pluginData: PluginData): void;
20+
static replace(compilation: Compilation, pluginData: PluginData, callback: (...args: any[]) => void): void;
21+
apply(compiler: Compiler): void;
22+
}
23+
export {};

index.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global.HtmlInlineCSSWebpackPlugin = factory());
5+
}(this, (function () { 'use strict';
6+
7+
var Plugin = /** @class */ (function () {
8+
function Plugin() {
9+
}
10+
Plugin.makeReg = function (fileName) {
11+
return new RegExp("<link[^>]+href=['\"]" + fileName + "['\"][^>]+(>|\\\\>|><\\/link>)");
12+
};
13+
Plugin.getStyleString = function (modules) {
14+
return modules
15+
.filter(function (_a) {
16+
var _b = _a.type, type = _b === void 0 ? '' : _b;
17+
return type.includes('mini-css-extract-plugin');
18+
})
19+
.reduce(function (result, _a) {
20+
var _b = _a.content, content = _b === void 0 ? '' : _b;
21+
return result + content;
22+
}, '');
23+
};
24+
Plugin.addStyleInToHTML = function (compilation, pluginData) {
25+
var style = this.getStyleString(compilation.modules);
26+
pluginData.html = pluginData.html
27+
.replace('</head>', "<style>\n" + style + "\n</style></head>");
28+
};
29+
Plugin.removeLinkTag = function (pluginData) {
30+
var _this = this;
31+
pluginData.assets.css.forEach(function (fileName) {
32+
pluginData.html = pluginData.html
33+
.replace(_this.makeReg(fileName), '');
34+
});
35+
};
36+
Plugin.replace = function (compilation, pluginData, callback) {
37+
Plugin.removeLinkTag(pluginData);
38+
Plugin.addStyleInToHTML(compilation, pluginData);
39+
callback(null, pluginData);
40+
};
41+
Plugin.prototype.apply = function (compiler) {
42+
compiler.hooks.compilation.tap('HtmlReplaceWebpackPlugin', function (compilation) {
43+
compilation.hooks.htmlWebpackPluginAfterHtmlProcessing
44+
.tapAsync('html-webpack-plugin-before-html-processing', Plugin.replace.bind(Plugin, compilation));
45+
});
46+
};
47+
return Plugin;
48+
}());
49+
50+
return Plugin;
51+
52+
})));

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"name": "html-inline-css-webpack-plugin",
33
"version": "0.0.1",
44
"description": "",
5-
"main": "./build/index.js",
5+
"main": "./index.js",
6+
"types": "./index.d.ts",
67
"scripts": {
7-
"build": "rm -rf ./build && tsc"
8+
"build": "rollup -c"
89
},
910
"repository": {
1011
"type": "git",
@@ -19,6 +20,8 @@
1920
"homepage": "https://github.com/Runjuu/html-inline-css-webpack-plugin#readme",
2021
"devDependencies": {
2122
"@types/webpack": "^4.4.0",
23+
"rollup": "^0.60.1",
24+
"rollup-plugin-typescript2": "^0.14.0",
2225
"tslib": "^1.9.2",
2326
"typescript": "^2.9.1",
2427
"webpack": "^4.11.1"

rollup.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import typescript from 'rollup-plugin-typescript2';
2+
3+
export default {
4+
input: './src/index.ts',
5+
output: {
6+
name: "HtmlInlineCSSWebpackPlugin",
7+
file: 'index.js',
8+
format: 'umd',
9+
},
10+
plugins: [typescript()],
11+
}

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"compilerOptions": {
33
"declaration": true,
44
"target": "es5",
5-
"module": "commonjs",
6-
"outDir": "build/",
5+
"module": "ES2015",
76
"sourceMap": true,
87
"experimentalDecorators": true,
98
"lib": ["dom", "es2015", "es2016"],

0 commit comments

Comments
 (0)