mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Hello Webpack4
This commit is contained in:
1 parent
0aa6183804
commit
06f1b5bc62
12 files changed
+350
-548
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
@@ -14,7 +14,7 @@ import vjGenerateLocales from '../plugins/gulpGenerateLocales';
|
|||||||
import vjTouch from '../plugins/gulpTouch';
|
import vjTouch from '../plugins/gulpTouch';
|
||||||
|
|
||||||
let isInWatchMode = false;
|
let isInWatchMode = false;
|
||||||
export let tasks = {};
|
export const tasks = {};
|
||||||
const iconTimestamp = moment.utc([2017, 0, 1, 0, 0, 0, 0]).unix();
|
const iconTimestamp = moment.utc([2017, 0, 1, 0, 0, 0, 0]).unix();
|
||||||
|
|
||||||
function handleWatchChange(name, r = 300) {
|
function handleWatchChange(name, r = 300) {
|
||||||
|
|||||||
+28
-87
@@ -1,22 +1,16 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
|
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
|
||||||
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
|
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
|
||||||
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
|
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
|
||||||
import ExtractTextPlugin from 'extract-text-webpack-plugin';
|
import ExtractCssPlugin from 'mini-css-extract-plugin';
|
||||||
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||||
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
|
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
|
||||||
import StaticManifestPlugin from '../plugins/webpackStaticManifestPlugin.js';
|
import StaticManifestPlugin from '../plugins/webpackStaticManifestPlugin';
|
||||||
import DummyOutputPlugin from '../plugins/webpackDummyOutputPlugin.js';
|
import mapWebpackUrlPrefix from '../utils/mapWebpackUrlPrefix';
|
||||||
import mapWebpackUrlPrefix from '../utils/mapWebpackUrlPrefix.js';
|
import root from '../utils/root';
|
||||||
import root from '../utils/root.js';
|
|
||||||
|
|
||||||
const extractProjectCSS = new ExtractTextPlugin({ filename: 'vj4.css?[sha1:contenthash:hex:10]', allChunks: true });
|
|
||||||
const extractVendorCSS = new ExtractTextPlugin({ filename: 'vendors.css?[sha1:contenthash:hex:10]', allChunks: true });
|
|
||||||
|
|
||||||
const beautifyOutputUrl = mapWebpackUrlPrefix([
|
const beautifyOutputUrl = mapWebpackUrlPrefix([
|
||||||
{ prefix: 'node_modules/katex/dist/', replace: 'katex/' },
|
{ prefix: 'node_modules/katex/dist/', replace: 'katex/' },
|
||||||
@@ -49,10 +43,6 @@ export default function (env = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonLoader() {
|
|
||||||
return 'json-loader';
|
|
||||||
}
|
|
||||||
|
|
||||||
function postcssLoader() {
|
function postcssLoader() {
|
||||||
return {
|
return {
|
||||||
loader: 'postcss-loader',
|
loader: 'postcss-loader',
|
||||||
@@ -62,18 +52,6 @@ export default function (env = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function styleLoader() {
|
|
||||||
return 'style-loader';
|
|
||||||
}
|
|
||||||
|
|
||||||
function cssLoader() {
|
|
||||||
return 'css-loader?importLoaders=1';
|
|
||||||
}
|
|
||||||
|
|
||||||
function stylusLoader() {
|
|
||||||
return 'stylus-loader';
|
|
||||||
}
|
|
||||||
|
|
||||||
function fileLoader() {
|
function fileLoader() {
|
||||||
return {
|
return {
|
||||||
loader: 'file-loader',
|
loader: 'file-loader',
|
||||||
@@ -83,8 +61,18 @@ export default function (env = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractCssLoader() {
|
||||||
|
return {
|
||||||
|
loader: ExtractCssPlugin.loader,
|
||||||
|
options: {
|
||||||
|
publicPath: '/public/path/to/',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
bail: true,
|
bail: true,
|
||||||
|
mode: 'production',
|
||||||
profile: true,
|
profile: true,
|
||||||
context: root(),
|
context: root(),
|
||||||
devtool: env.production ? 'source-map' : false,
|
devtool: env.production ? 'source-map' : false,
|
||||||
@@ -112,7 +100,7 @@ export default function (env = {}) {
|
|||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.jsx?$/,
|
test: /\.jsx?$/,
|
||||||
exclude: /node_modules[\/\\]/,
|
exclude: /node_modules[/\\]/,
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
use: [eslintLoader()],
|
use: [eslintLoader()],
|
||||||
},
|
},
|
||||||
@@ -124,13 +112,9 @@ export default function (env = {}) {
|
|||||||
{
|
{
|
||||||
// ES2015 scripts
|
// ES2015 scripts
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
exclude: /node_modules[\/\\]/,
|
exclude: /node_modules[/\\]/,
|
||||||
use: [babelLoader()],
|
use: [babelLoader()],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
test: /\.json$/,
|
|
||||||
use: [jsonLoader()],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
// fix pickadate loading
|
// fix pickadate loading
|
||||||
test: /pickadate/,
|
test: /pickadate/,
|
||||||
@@ -142,35 +126,23 @@ export default function (env = {}) {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// project stylus stylesheets
|
|
||||||
test: /\.styl$/,
|
test: /\.styl$/,
|
||||||
use: env.watch
|
use: [extractCssLoader(), 'css-loader?importLoaders=1', postcssLoader(), 'stylus-loader']
|
||||||
? [styleLoader(), cssLoader(), postcssLoader(), stylusLoader()]
|
|
||||||
: extractProjectCSS.extract([cssLoader(), postcssLoader(), stylusLoader()])
|
|
||||||
,
|
,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// vendors stylesheets
|
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
include: /node_modules[\/\\]/,
|
use: [extractCssLoader(), 'css-loader?importLoaders=1', postcssLoader()]
|
||||||
use: env.watch
|
|
||||||
? [styleLoader(), cssLoader()]
|
|
||||||
: extractVendorCSS.extract([cssLoader()])
|
|
||||||
,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// project stylesheets
|
|
||||||
test: /\.css$/,
|
|
||||||
exclude: /node_modules[\/\\]/,
|
|
||||||
use: env.watch
|
|
||||||
? [styleLoader(), cssLoader(), postcssLoader()]
|
|
||||||
: extractProjectCSS.extract([cssLoader(), postcssLoader()])
|
|
||||||
,
|
,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
optimization: {
|
||||||
|
splitChunks: {
|
||||||
|
minChunks: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
$: 'jquery',
|
$: 'jquery',
|
||||||
jQuery: 'jquery',
|
jQuery: 'jquery',
|
||||||
@@ -186,41 +158,12 @@ export default function (env = {}) {
|
|||||||
|
|
||||||
new MonacoWebpackPlugin({
|
new MonacoWebpackPlugin({
|
||||||
// available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
|
// available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
|
||||||
languages: ['cpp', 'csharp', 'java', 'javascript', 'python', 'rust', 'ruby', 'php', 'pascal', 'go']
|
languages: ['cpp', 'csharp', 'java', 'javascript', 'python', 'rust', 'ruby', 'php', 'pascal', 'go'],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// extract stylesheets into a standalone file
|
new ExtractCssPlugin({
|
||||||
env.watch
|
filename: 'vj4.css?[contenthash:10]',
|
||||||
? new DummyOutputPlugin('vendors.css')
|
allChunks: true,
|
||||||
: extractVendorCSS,
|
|
||||||
|
|
||||||
env.watch
|
|
||||||
? new DummyOutputPlugin('vj4.css')
|
|
||||||
: extractProjectCSS,
|
|
||||||
|
|
||||||
// extract 3rd-party JavaScript libraries into a standalone file
|
|
||||||
env.watch
|
|
||||||
? new DummyOutputPlugin('vendors.js')
|
|
||||||
: new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'vendors',
|
|
||||||
minChunks: (module, count) => (
|
|
||||||
module.resource
|
|
||||||
&& module.resource.indexOf(root('node_modules'))
|
|
||||||
&& module.resource.match(/\.jsx?$/)
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
|
|
||||||
// extract manifest into a standalone file
|
|
||||||
env.watch
|
|
||||||
? new DummyOutputPlugin('manifest.js')
|
|
||||||
: new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'manifest',
|
|
||||||
}),
|
|
||||||
|
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
children: true,
|
|
||||||
async: true,
|
|
||||||
minChunks: 2,
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// copy static assets
|
// copy static assets
|
||||||
@@ -272,8 +215,6 @@ export default function (env = {}) {
|
|||||||
new webpack.LoaderOptionsPlugin({
|
new webpack.LoaderOptionsPlugin({
|
||||||
options: {
|
options: {
|
||||||
context: root(),
|
context: root(),
|
||||||
|
|
||||||
// Beautify the output path of assets
|
|
||||||
customInterpolateName: (url, name, options) => beautifyOutputUrl(url),
|
customInterpolateName: (url, name, options) => beautifyOutputUrl(url),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import { argv } from 'yargs';
|
import { argv } from 'yargs';
|
||||||
import root from './utils/root';
|
import root from './utils/root';
|
||||||
import runGulp from './runGulp';
|
import runGulp from './runGulp';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
|
|
||||||
import PluginError from 'plugin-error';
|
import PluginError from 'plugin-error';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import PluginError from 'plugin-error';
|
import PluginError from 'plugin-error';
|
||||||
import through from 'through2';
|
import through from 'through2';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
export default class DummyOutputPlugin {
|
|
||||||
constructor(file) {
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
apply(compiler) {
|
|
||||||
compiler.plugin('emit', (compilation, callback) => {
|
|
||||||
compilation.assets[this.file] = {
|
|
||||||
source: () => '',
|
|
||||||
size: () => 0,
|
|
||||||
};
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -1,9 +1,8 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import _ from 'lodash';
|
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
import log from 'fancy-log';
|
import log from 'fancy-log';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import gulpConfig from './config/gulp.js';
|
import gulpConfig from './config/gulp';
|
||||||
|
|
||||||
export default async function ({ watch, production }) {
|
export default async function ({ watch, production }) {
|
||||||
function handleError(err) {
|
function handleError(err) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import root from './utils/root';
|
import root from './utils/root';
|
||||||
@@ -8,12 +8,6 @@ export default function ({ watch, production }) {
|
|||||||
const compiler = webpack(webpackConfig({ watch, production }));
|
const compiler = webpack(webpackConfig({ watch, production }));
|
||||||
compiler.apply(new webpack.ProgressPlugin());
|
compiler.apply(new webpack.ProgressPlugin());
|
||||||
|
|
||||||
const outputOptions = {
|
|
||||||
colors: true,
|
|
||||||
errorDetails: true,
|
|
||||||
optimizationBailout: production,
|
|
||||||
};
|
|
||||||
|
|
||||||
function compilerCallback(err, stats) {
|
function compilerCallback(err, stats) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.stack || err);
|
console.error(err.stack || err);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export default function mapWebpackUrlPrefix(mapList) {
|
export default function mapWebpackUrlPrefix(mapList) {
|
||||||
|
|||||||
+3
-4
@@ -37,7 +37,6 @@
|
|||||||
"eslint-plugin-import": "^2.17.2",
|
"eslint-plugin-import": "^2.17.2",
|
||||||
"eslint-plugin-jsx-a11y": "^6.2.1",
|
"eslint-plugin-jsx-a11y": "^6.2.1",
|
||||||
"eslint-plugin-react": "^7.13.0",
|
"eslint-plugin-react": "^7.13.0",
|
||||||
"extract-text-webpack-plugin": "^3.0.2",
|
|
||||||
"file-loader": "^2.0.0",
|
"file-loader": "^2.0.0",
|
||||||
"friendly-errors-webpack-plugin": "^1.7.0",
|
"friendly-errors-webpack-plugin": "^1.7.0",
|
||||||
"fs-extra": "^8.0.1",
|
"fs-extra": "^8.0.1",
|
||||||
@@ -52,7 +51,7 @@
|
|||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"json-loader": "^0.5.7",
|
"json-loader": "^0.5.7",
|
||||||
"monaco-editor-webpack-plugin": "^1.9.0",
|
"monaco-editor-webpack-plugin": "^1.9.0",
|
||||||
"optimize-css-assets-webpack-plugin": "^3.2.0",
|
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
||||||
"postcss-loader": "^3.0.0",
|
"postcss-loader": "^3.0.0",
|
||||||
"rupture": "^0.7.1",
|
"rupture": "^0.7.1",
|
||||||
"style-loader": "^0.23.1",
|
"style-loader": "^0.23.1",
|
||||||
@@ -61,7 +60,7 @@
|
|||||||
"through2": "^3.0.1",
|
"through2": "^3.0.1",
|
||||||
"uglifyjs-webpack-plugin": "^1.3.0",
|
"uglifyjs-webpack-plugin": "^1.3.0",
|
||||||
"vinyl-buffer": "^1.0.1",
|
"vinyl-buffer": "^1.0.1",
|
||||||
"webpack": "^3.12.0",
|
"webpack": "^4.42.1",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -79,6 +78,7 @@
|
|||||||
"jquery.transit": "^0.9.12",
|
"jquery.transit": "^0.9.12",
|
||||||
"katex": "^0.10.2",
|
"katex": "^0.10.2",
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
|
"mini-css-extract-plugin": "^0.9.0",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
@@ -110,7 +110,6 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build",
|
"build": "node build",
|
||||||
"build:production": "node build --production",
|
"build:production": "node build --production",
|
||||||
"build:watch": "node build --watch",
|
|
||||||
"lint": "eslint --fix ."
|
"lint": "eslint --fix ."
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
|
|||||||
+309
-424
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user