Merge pull request #656 from embark-framework/bug_fix/dot.embark_versions_modules

.embark/versions modules
This commit is contained in:
Iuri Matias 2018-07-30 12:54:43 -04:00 committed by GitHub
commit a58f21c303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 136 deletions

View File

@ -6,6 +6,7 @@ const constants = require('../constants');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const ProcessWrapper = require('../core/processes/processWrapper'); const ProcessWrapper = require('../core/processes/processWrapper');
const path = require('path'); const path = require('path');
const glob = require('glob');
let webpackProcess; let webpackProcess;
@ -42,142 +43,152 @@ class WebpackProcess extends ProcessWrapper {
webpackRun(filename, options, includeModules, importsList, detectErrors, realCwd, callback) { webpackRun(filename, options, includeModules, importsList, detectErrors, realCwd, callback) {
const self = this; const self = this;
let defaultOptions = { glob(fs.dappPath('.embark/versions') + '/*/*', (err, files) => {
mode: self.env === 'production' ? 'production' : 'none', let versions;
// devtool: self.env === 'development' ? 'source-map' : false, if (err) {
// pipeline would need to copy .map files to dist/ target dir console.error(err);
// note: generating full source maps ('source-map') roughly doubles build time versions = [];
entry: fs.dappPath(filename), } else {
output: { versions = files;
globalObject: 'typeof self !== \'undefined\' ? self : this', }
libraryExport: 'default', let defaultOptions = {
libraryTarget: 'umd', mode: self.env === 'production' ? 'production' : 'none',
path: fs.dappPath('.embark'), // devtool: self.env === 'development' ? 'source-map' : false,
filename: filename, // pipeline would need to copy .map files to dist/ target dir
umdNamedDefine: true // note: generating full source maps ('source-map') roughly doubles build time
}, entry: fs.dappPath(filename),
// profile: true, output: {
// stats: 'verbose', globalObject: 'typeof self !== \'undefined\' ? self : this',
// note: generating and writing to disk verbose stats increases build time libraryExport: 'default',
resolve: { libraryTarget: 'umd',
alias: importsList, path: fs.dappPath('.embark'),
modules: [ filename: filename,
fs.embarkPath('node_modules'), umdNamedDefine: true
fs.dappPath('node_modules') },
] // profile: true,
}, // stats: 'verbose',
plugins: [ // note: generating and writing to disk verbose stats increases build time
new HardSourceWebpackPlugin({ resolve: {
cacheDirectory: fs.dappPath('node_modules/.cache/hard-source'), alias: importsList,
// ufglify (wp mode: production) will still save its cache in embark's node_modules/.cache/ modules: [
environmentHash: { fs.dappPath('node_modules'),
root: fs.dappPath() ...versions,
} fs.embarkPath('node_modules')
}), ]
new HardSourceWebpackPlugin.ExcludeModulePlugin( },
[{test: /app[\\/]|contracts[\\/]/}] plugins: [
) new HardSourceWebpackPlugin({
] cacheDirectory: fs.dappPath('node_modules/.cache/hard-source'),
}; // ufglify (wp mode: production) will still save its cache in embark's node_modules/.cache/
environmentHash: {
let webpackOptions = utils.recursiveMerge(defaultOptions, options); root: fs.dappPath()
if (includeModules) {
webpackOptions.module = {
rules: [
{
test: /\.css$/,
use: [{loader: "style-loader"}, {loader: "css-loader"}]
},
{
test: /\.scss$/,
use: [{loader: "style-loader"}, {loader: "css-loader"}]
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
},
{
test: /\.js$/,
loader: "babel-loader",
exclude: /(node_modules|bower_components)/,
options: {
presets: [
[
"@babel/preset-env", {
modules: false,
targets: {
browsers: ["last 1 version", "not dead", "> 0.2%"]
}
}
],
"@babel/preset-react"
].map(pkg => {
if (Array.isArray(pkg)) {
let _pkg = pkg[0];
pkg[0] = require.resolve(_pkg);
return pkg;
} else {
return require.resolve(pkg);
}
}),
plugins: [
"@babel/plugin-transform-runtime",
"babel-plugin-webpack-aliases"
].map(require.resolve),
compact: false
} }
} }),
new HardSourceWebpackPlugin.ExcludeModulePlugin(
[{test: /app[\\/]|contracts[\\/]/}]
)
] ]
}; };
let dappBabelrc = path.join(realCwd, '.babelrc'); let webpackOptions = utils.recursiveMerge(defaultOptions, options);
if (fs.existsSync(dappBabelrc)) {
webpackOptions.module.rules[3].options.extends = dappBabelrc;
}
}
webpack(webpackOptions).run((err, stats) => { if (includeModules) {
async.waterfall([ webpackOptions.module = {
function checkStatsError(next) { rules: [
if (err) { {
console.error(err); test: /\.css$/,
return next(err); use: [{loader: "style-loader"}, {loader: "css-loader"}]
} },
if (!detectErrors) { {
return next(); test: /\.scss$/,
} use: [{loader: "style-loader"}, {loader: "css-loader"}]
if (stats.hasErrors()) { },
return next( {
stats.toJson(webpackOptions.stats).errors.join("\n") test: /\.(png|woff|woff2|eot|ttf|svg)$/,
); loader: 'url-loader?limit=100000'
} },
next(); {
}//, test: /\.js$/,
// function writeStatsReport(next) { loader: "babel-loader",
// if (detectErrors) { exclude: /(node_modules|bower_components|\.embark\/versions)/,
// self._log('info', 'writing file '+ ('.embark/stats.report').bold.dim); options: {
// } presets: [
// fs.writeFile( [
// path.join(fs.dappPath('.embark'), 'stats.report'), "@babel/preset-env", {
// stats.toString(webpackOptions.stats), modules: false,
// next targets: {
// ); browsers: ["last 1 version", "not dead", "> 0.2%"]
// }, }
// function writeStatsJSON(next) { }
// if (detectErrors) { ],
// self._log('info','writing file '+ ('.embark/stats.json').bold.dim); "@babel/preset-react"
// } ].map(pkg => {
// fs.writeFile( if (Array.isArray(pkg)) {
// path.join(fs.dappPath('.embark'), 'stats.json'), let _pkg = pkg[0];
// JSON.stringify(stats.toJson(webpackOptions.stats)), pkg[0] = require.resolve(_pkg);
// next return pkg;
// ); } else {
// } return require.resolve(pkg);
// note: to visualize the stats info in a browser, do... }
// `npx webpack-bundle-analyzer <dapp_dir>/.embark/stats.json` }),
], (err) => { plugins: [
callback(err); "babel-plugin-webpack-aliases",
"@babel/plugin-transform-runtime"
].map(require.resolve),
compact: false
}
}
]
};
let dappBabelrc = path.join(realCwd, '.babelrc');
if (fs.existsSync(dappBabelrc)) {
webpackOptions.module.rules[3].options.extends = dappBabelrc;
}
}
webpack(webpackOptions).run((err, stats) => {
async.waterfall([
function checkStatsError(next) {
if (err) {
console.error(err);
return next(err);
}
if (!detectErrors) {
return next();
}
if (stats.hasErrors()) {
return next(
stats.toJson(webpackOptions.stats).errors.join("\n")
);
}
next();
}//,
// function writeStatsReport(next) {
// if (detectErrors) {
// self._log('info', 'writing file '+ ('.embark/stats.report').bold.dim);
// }
// fs.writeFile(
// path.join(fs.dappPath('.embark'), 'stats.report'),
// stats.toString(webpackOptions.stats),
// next
// );
// },
// function writeStatsJSON(next) {
// if (detectErrors) {
// self._log('info','writing file '+ ('.embark/stats.json').bold.dim);
// }
// fs.writeFile(
// path.join(fs.dappPath('.embark'), 'stats.json'),
// JSON.stringify(stats.toJson(webpackOptions.stats)),
// next
// );
// }
// note: to visualize the stats info in a browser, do...
// `npx webpack-bundle-analyzer <dapp_dir>/.embark/stats.json`
], (err) => {
callback(err);
});
}); });
}); });
} }

View File

@ -21,10 +21,11 @@
"url": "https://github.com/embark-framework/embark.git" "url": "https://github.com/embark-framework/embark.git"
}, },
"dependencies": { "dependencies": {
"@babel/core": "7.0.0-beta.54", "@babel/core": "^7.0.0-beta.54",
"@babel/plugin-transform-runtime": "7.0.0-beta.54", "@babel/plugin-transform-runtime": "^7.0.0-beta.54",
"@babel/preset-env": "7.0.0-beta.54", "@babel/preset-env": "^7.0.0-beta.54",
"@babel/preset-react": "7.0.0-beta.54", "@babel/preset-react": "^7.0.0-beta.54",
"@babel/runtime": "^7.0.0-beta.54",
"ascii-table": "0.0.9", "ascii-table": "0.0.9",
"async": "^2.0.1", "async": "^2.0.1",
"babel-loader": "^8.0.0-beta.4", "babel-loader": "^8.0.0-beta.4",
@ -47,6 +48,7 @@
"follow-redirects": "^1.2.4", "follow-redirects": "^1.2.4",
"fs-extra": "^2.0.0", "fs-extra": "^2.0.0",
"ganache-cli": "6.1.0", "ganache-cli": "6.1.0",
"glob": "^7.1.2",
"globule": "^1.1.0", "globule": "^1.1.0",
"hard-source-webpack-plugin": "^0.11.1", "hard-source-webpack-plugin": "^0.11.1",
"http-proxy": "^1.17.0", "http-proxy": "^1.17.0",

View File

@ -10,7 +10,7 @@
"license": "ISC", "license": "ISC",
"homepage": "", "homepage": "",
"devDependencies": { "devDependencies": {
"babel-code-frame": "^6.26.0" "@babel/code-frame": "^7.0.0-beta.54"
}, },
"dependencies": { "dependencies": {
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",