Permalink
Browse files

💥 webpack 4

  • Loading branch information...
MoOx committed Nov 26, 2018
1 parent e268c6a commit 7405e56f1dfa0bd404bcbfcc64d0bb5c9fa8a680

This file was deleted.

Oops, something went wrong.
@@ -29,6 +29,7 @@ const log = (

export default (sender: string, writer: WriterType = console.log) => {
const logger = (msg: string) => log(sender, INFO, msg, writer);
logger.trace = (msg: string) => log(sender, null, msg, writer);
logger.debug = (msg: string) => log(sender, null, msg, writer);
logger.info = (msg: string) => log(sender, INFO, msg, writer);
logger.success = (msg: string) => log(sender, SUCCESS, msg, writer);
@@ -27,16 +27,16 @@
"@phenomic/babel-preset": "^1.0.0-beta.4",
"babel-loader": "^7.0.0",
"chalk": "^1.1.3",
"css-loader": "^0.28.0",
"css-loader": "^1.0.0",
"debug": "^2.6.0",
"extract-text-webpack-plugin": "^3.0.0",
"find-cache-dir": "^0.1.1",
"multili": "^1.1.0",
"source-map-support": "^0.4.0",
"mini-css-extract-plugin": "^0.4.0",
"source-map-support": "^0.5.0",
"style-loader": "^0.16.1",
"webpack": "^3.0.0",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.18.0"
"webpack": "^4.0.0",
"webpack-dev-middleware": "^3.0.0",
"webpack-hot-middleware": "^2.0.0"
},
"peerDependencies": {
"@phenomic/core": "^1.0.0-beta.3"
@@ -2,21 +2,21 @@

import path from "path";
import fs from "fs";
// import url from "url"

// import pkg from "@phenomic/core/package.json"
import findCacheDir from "find-cache-dir";
// import webpack, { BannerPlugin, optimize, DefinePlugin } from "webpack"
import webpack, { BannerPlugin, optimize } from "webpack";
import webpack, { BannerPlugin } from "webpack";
import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import logger from "@phenomic/core/lib/logger";

import webpackPromise from "./webpack-promise.js";
import validate from "./validate.js";

const debug = require("debug")("phenomic:plugin:bundler-webpack");

const { UglifyJsPlugin } = optimize;
const pluginName = "@phenomic/plugin-bundler-webpack";
const log = logger(pluginName);

const cacheDir = findCacheDir({ name: "phenomic/webpack", create: true });
const requireSourceMapSupport = `require('${require
.resolve("source-map-support/register")
@@ -80,16 +80,16 @@ const getWebpackConfig = (config: PhenomicConfig) => {

const bundlerWebpack: PhenomicPluginModule<{}> = config => {
return {
name: "@phenomic/plugin-bundler-webpack",
name: pluginName,
addDevServerMiddlewares() {
debug("get middlewares");
const compiler = webpack(getWebpackConfig(config));
let assets = {};
compiler.plugin("done", stats => {
compiler.hooks.done.tap(pluginName + "/dev-server-middleware", stats => {
assets = {};
const namedChunks = stats.compilation.namedChunks;
Object.keys(namedChunks).forEach(chunkName => {
const files = namedChunks[chunkName].files.filter(
namedChunks.forEach((chunk, chunkName) => {
const files = chunk.files.filter(
file => !file.endsWith(".hot-update.js"),
);
if (files.length) {
@@ -110,16 +110,14 @@ const bundlerWebpack: PhenomicPluginModule<{}> = config => {
next();
},
webpackDevMiddleware(compiler, {
logLevel: "warn",
publicPath: config.baseUrl.pathname,
stats: { chunkModules: false, assets: false },
// @todo add this and output ourself a nice message for build status
// noInfo: true,
// quiet: true,
// logger: log, // output info even if logLevel: "warn"
}),
webpackHotMiddleware(compiler, {
reload: true,
// skip hot middleware logs if !verbose
// log: config.verbose ? undefined : () => {},
log,
}),
];
},
@@ -144,12 +142,7 @@ const bundlerWebpack: PhenomicPluginModule<{}> = config => {
libraryTarget: "commonjs2",
},
plugins: [
// Remove UglifyJSPlugin from plugin stack
...(webpackConfig.plugins
? webpackConfig.plugins.filter(
plugin => !(plugin instanceof UglifyJsPlugin),
)
: []),
...webpackConfig.plugins,
// sourcemaps
new BannerPlugin({
banner: requireSourceMapSupport,
@@ -4,9 +4,11 @@ import path from "path";

import getClientEnvironment from "@phenomic/core/lib/configuration/get-client-environment.js";
import webpack from "webpack";
import ExtractTextPlugin from "extract-text-webpack-plugin";
// $FlowFixMe lazy me
import MiniCssExtractPlugin from "mini-css-extract-plugin";

module.exports = (config: PhenomicConfig) => ({
mode: process.env.NODE_ENV,
entry: {
[config.bundleName]: [
process.env.PHENOMIC_ENV !== "static" &&
@@ -34,26 +36,33 @@ module.exports = (config: PhenomicConfig) => ({
{
test: /\.js$/,
exclude: /node_modules/,
loader: require.resolve("babel-loader"),
options: {
babelrc: false,
presets: [require.resolve("@phenomic/babel-preset")],
},
use: [
{
loader: require.resolve("babel-loader"),
options: {
babelrc: false,
presets: [require.resolve("@phenomic/babel-preset")],
},
},
],
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: require.resolve("style-loader"),
use: require.resolve("css-loader"),
}),
use: [
process.env.PHENOMIC_ENV !== "static"
? "style-loader"
: MiniCssExtractPlugin.loader,
require.resolve("css-loader"),
],
},
],
},
plugins: [
new ExtractTextPlugin({
filename: "phenomic/[name].[contenthash:8].css",
disable: process.env.PHENOMIC_ENV !== "static",
}),
process.env.PHENOMIC_ENV === "static" &&
new MiniCssExtractPlugin({
filename: "phenomic/[name].[chunkhash:8].css",
chunkFilename: "phenomic/[name].[chunkhash:8].chunk.css",
}),
(() => {
const envVars = getClientEnvironment(config);
return new webpack.DefinePlugin({
@@ -65,8 +74,6 @@ module.exports = (config: PhenomicConfig) => ({
})(),
process.env.PHENOMIC_ENV !== "static" &&
new webpack.HotModuleReplacementPlugin(),
process.env.NODE_ENV === "production" &&
new webpack.optimize.UglifyJsPlugin(),
].filter(item => item),

resolve: {
Oops, something went wrong.

0 comments on commit 7405e56

Please sign in to comment.