Skip to content

optimize source code #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { Template } = webpack;

const NS = path.dirname(fs.realpathSync(__filename));

const pluginName = 'mini-css-extract-plugin';

class CssDependency extends webpack.Dependency {
constructor({ identifier, content, media, sourceMap }, context, identifierIndex) {
super();
Expand Down Expand Up @@ -93,8 +95,8 @@ class MiniCssExtractPlugin {
}

apply(compiler) {
compiler.hooks.thisCompilation.tap('mini-css-extract-plugin', (compilation) => {
compilation.hooks.normalModuleLoader.tap('mini-css-extract-plugin', (lc, m) => {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.normalModuleLoader.tap(pluginName, (lc, m) => {
const loaderContext = lc;
const module = m;
loaderContext[NS] = (content) => {
Expand All @@ -111,7 +113,7 @@ class MiniCssExtractPlugin {
});
compilation.dependencyFactories.set(CssDependency, new CssModuleFactory());
compilation.dependencyTemplates.set(CssDependency, new CssDependencyTemplate());
compilation.mainTemplate.hooks.renderManifest.tap('mini-css-extract-plugin', (result, { chunk }) => {
compilation.mainTemplate.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
const renderedModules = Array.from(chunk.modulesIterable).filter(module => module.type === NS);
if (renderedModules.length > 0) {
result.push({
Expand All @@ -124,7 +126,7 @@ class MiniCssExtractPlugin {
});
}
});
compilation.chunkTemplate.hooks.renderManifest.tap('mini-css-extract-plugin', (result, { chunk }) => {
compilation.chunkTemplate.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
const renderedModules = Array.from(chunk.modulesIterable).filter(module => module.type === NS);
if (renderedModules.length > 0) {
result.push({
Expand All @@ -139,7 +141,7 @@ class MiniCssExtractPlugin {
});
const { mainTemplate } = compilation;
mainTemplate.hooks.localVars.tap(
'mini-css-extract-plugin',
pluginName,
(source, chunk) => {
const chunkMap = this.getCssChunkObject(chunk);
if (Object.keys(chunkMap).length > 0) {
Expand All @@ -158,7 +160,7 @@ class MiniCssExtractPlugin {
},
);
mainTemplate.hooks.requireEnsure.tap(
'mini-css-extract-plugin',
pluginName,
(source, chunk, hash) => {
const chunkMap = this.getCssChunkObject(chunk);
if (Object.keys(chunkMap).length > 0) {
Expand Down