mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
Modify config for production build, add build command
This commit is contained in:
parent
85f9a5ff02
commit
af5c34c6fd
5
cli.js
5
cli.js
@ -13,6 +13,11 @@ program
|
||||
.description('Start development server')
|
||||
.action(require('./webpack/start'))
|
||||
|
||||
program
|
||||
.command('build [mode]')
|
||||
.description('Build assets for production')
|
||||
.action(require('./webpack/build'))
|
||||
|
||||
program
|
||||
.command('new-model <name>')
|
||||
.description('Create a new model in the `models/doctype` folder')
|
||||
|
@ -20,6 +20,7 @@
|
||||
"case-sensitive-paths-webpack-plugin": "^2.1.2",
|
||||
"codemirror": "^5.35.0",
|
||||
"commander": "^2.13.0",
|
||||
"copy-webpack-plugin": "^4.5.4",
|
||||
"cors": "^2.8.4",
|
||||
"css-loader": "^1.0.0",
|
||||
"deepmerge": "^2.1.0",
|
||||
|
47
webpack/build.js
Normal file
47
webpack/build.js
Normal file
@ -0,0 +1,47 @@
|
||||
const webpack = require('webpack');
|
||||
const getWebpackConfig = require('./config');
|
||||
|
||||
module.exports = function build(mode) {
|
||||
const webpackConfig = getWebpackConfig();
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
if (mode === 'electron') {
|
||||
pack(webpackConfig)
|
||||
.then(result => {
|
||||
console.log(result);
|
||||
}).catch(err => {
|
||||
console.log(`\n Failed to build renderer process`);
|
||||
console.error(`\n${err}\n`);
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function pack(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
webpack(config, (err, stats) => {
|
||||
if (err) reject(err.stack || err)
|
||||
|
||||
else if (stats.hasErrors()) {
|
||||
let err = ''
|
||||
|
||||
stats
|
||||
.toString({
|
||||
chunks: false,
|
||||
colors: true
|
||||
})
|
||||
.split(/\r?\n/)
|
||||
.forEach(line => {
|
||||
err += ` ${line}\n`
|
||||
});
|
||||
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(stats.toString({
|
||||
chunks: false,
|
||||
colors: true
|
||||
}));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const { getAppConfig, resolveAppDir } = require('./utils');
|
||||
const appPackageJson = require(resolveAppDir('./package.json'));
|
||||
const appDependencies = appPackageJson.dependencies;
|
||||
const appDependencies = require(resolveAppDir('./package.json')).dependencies;
|
||||
const frappeDependencies = require('../package.json').dependencies;
|
||||
const allDependencies = Object.assign(frappeDependencies, appDependencies);
|
||||
|
||||
const plugins = {
|
||||
function getConfig() {
|
||||
const plugins = {
|
||||
NamedModules: webpack.NamedModulesPlugin,
|
||||
HotModuleReplacement: webpack.HotModuleReplacementPlugin,
|
||||
Define: webpack.DefinePlugin,
|
||||
@ -15,149 +13,143 @@ const plugins = {
|
||||
Html: require('html-webpack-plugin'),
|
||||
CaseSensitivePaths: require('case-sensitive-paths-webpack-plugin'),
|
||||
FriendlyErrors: require('friendly-errors-webpack-plugin'),
|
||||
}
|
||||
CopyWebpackPlugin: require('copy-webpack-plugin')
|
||||
}
|
||||
|
||||
const appConfig = getAppConfig();
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const isElectron = process.env.ELECTRON === 'true';
|
||||
const isMonoRepo = process.env.MONO_REPO === 'true';
|
||||
const appConfig = getAppConfig();
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const isElectron = process.env.ELECTRON === 'true';
|
||||
const isMonoRepo = process.env.MONO_REPO === 'true';
|
||||
|
||||
const whiteListedModules = ['vue'];
|
||||
const externals = Object.keys(allDependencies).filter(d => !whiteListedModules.includes(d))
|
||||
const whiteListedModules = ['vue'];
|
||||
const allDependencies = Object.assign(frappeDependencies, appDependencies);
|
||||
const externals = Object.keys(allDependencies).filter(d => !whiteListedModules.includes(d))
|
||||
|
||||
console.log(externals);
|
||||
|
||||
function getConfig() {
|
||||
const config = {
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
context: resolveAppDir(),
|
||||
entry: isElectron ? appConfig.electron.entry : appConfig.dev.entry,
|
||||
externals: isElectron ? externals : null,
|
||||
target: isElectron ? 'electron-renderer' : 'web',
|
||||
output: {
|
||||
path: isElectron ? resolveAppDir('./dist/electron') : resolveAppDir('./dist'),
|
||||
filename: '[name].js',
|
||||
publicPath: appConfig.dev.assetsPublicPath,
|
||||
libraryTarget: isElectron ? 'commonjs2' : null
|
||||
const config = {
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
context: resolveAppDir(),
|
||||
entry: isElectron ? appConfig.electron.entry : appConfig.dev.entry,
|
||||
externals: isElectron ? externals : null,
|
||||
target: isElectron ? 'electron-renderer' : 'web',
|
||||
output: {
|
||||
path: isElectron ? resolveAppDir('./dist/electron') : resolveAppDir('./dist'),
|
||||
filename: '[name].js',
|
||||
// publicPath: appConfig.dev.assetsPublicPath,
|
||||
libraryTarget: isElectron ? 'commonjs2' : null
|
||||
},
|
||||
devtool: !isProduction ? 'cheap-module-eval-source-map' : '',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader'
|
||||
},
|
||||
devtool: 'cheap-module-eval-source-map',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader'
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: file => (
|
||||
/node_modules/.test(file) &&
|
||||
!/\.vue\.js/.test(file)
|
||||
)
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader'
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
'css-loader'
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
'css-loader',
|
||||
'sass-loader'
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(png|svg|jpg|gif)$/,
|
||||
use: [
|
||||
'file-loader'
|
||||
]
|
||||
}
|
||||
]
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: file => (
|
||||
/node_modules/.test(file) &&
|
||||
!/\.vue\.js/.test(file)
|
||||
)
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js', '.vue', '.json', '.css', '.node'],
|
||||
alias: {
|
||||
'vue$': 'vue/dist/vue.esm.js',
|
||||
'deepmerge$': 'deepmerge/dist/umd.js',
|
||||
'@': appConfig.dev.srcDir ? resolveAppDir(appConfig.dev.srcDir) : null
|
||||
}
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader'
|
||||
},
|
||||
plugins: [
|
||||
new plugins.Define({
|
||||
'process.env': appConfig.dev.env
|
||||
}),
|
||||
new plugins.VueLoader(),
|
||||
new plugins.Html({
|
||||
template: resolveAppDir(appConfig.dev.entryHtml),
|
||||
nodeModules: !isProduction
|
||||
? isMonoRepo ? resolveAppDir('../../node_modules') : resolveAppDir('./node_modules')
|
||||
: false
|
||||
}),
|
||||
new plugins.CaseSensitivePaths(),
|
||||
new plugins.NamedModules(),
|
||||
new plugins.HotModuleReplacement(),
|
||||
new plugins.FriendlyErrors({
|
||||
compilationSuccessInfo: {
|
||||
messages: [`FrappeJS server started at http://${appConfig.dev.devServerHost}:${appConfig.dev.devServerPort}`],
|
||||
},
|
||||
}),
|
||||
new plugins.Progress()
|
||||
],
|
||||
optimization: {
|
||||
noEmitOnErrors: false
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
'css-loader'
|
||||
]
|
||||
},
|
||||
devServer: {
|
||||
// contentBase: './dist', // dist path is directly configured in express
|
||||
hot: true,
|
||||
quiet: true
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
'css-loader',
|
||||
'sass-loader'
|
||||
]
|
||||
},
|
||||
node: {
|
||||
// prevent webpack from injecting useless setImmediate polyfill because Vue
|
||||
// source contains it (although only uses it if it's native).
|
||||
setImmediate: false,
|
||||
// process is injected via DefinePlugin, although some 3rd party
|
||||
// libraries may require a mock to work properly (#934)
|
||||
process: 'mock',
|
||||
// prevent webpack from injecting mocks to Node native modules
|
||||
// that does not make sense for the client
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty'
|
||||
{
|
||||
test: /\.(png|svg|jpg|gif)$/,
|
||||
use: [
|
||||
'file-loader'
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js', '.vue', '.json', '.css', '.node'],
|
||||
alias: {
|
||||
'vue$': 'vue/dist/vue.esm.js',
|
||||
'deepmerge$': 'deepmerge/dist/umd.js',
|
||||
'@': appConfig.dev.srcDir ? resolveAppDir(appConfig.dev.srcDir) : null
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new plugins.Define(Object.assign({
|
||||
'process.env': appConfig.dev.env,
|
||||
'process.env.NODE_ENV': isProduction ? '"production"' : '"development"',
|
||||
}, !isProduction ? {
|
||||
'__static': `"${resolveAppDir(appConfig.staticPath).replace(/\\/g, '\\\\')}"`
|
||||
} : {})),
|
||||
new plugins.VueLoader(),
|
||||
new plugins.Html({
|
||||
template: resolveAppDir(appConfig.dev.entryHtml),
|
||||
nodeModules: !isProduction
|
||||
? isMonoRepo ? resolveAppDir('../../node_modules') : resolveAppDir('./node_modules')
|
||||
: false
|
||||
}),
|
||||
new plugins.CaseSensitivePaths(),
|
||||
new plugins.NamedModules(),
|
||||
new plugins.HotModuleReplacement(),
|
||||
new plugins.FriendlyErrors({
|
||||
compilationSuccessInfo: {
|
||||
messages: [`FrappeJS server started at http://${appConfig.dev.devServerHost}:${appConfig.dev.devServerPort}`],
|
||||
},
|
||||
}),
|
||||
new plugins.Progress(),
|
||||
isProduction ? new plugins.CopyWebpackPlugin([
|
||||
{
|
||||
from: resolveAppDir(appConfig.staticPath),
|
||||
to: resolveAppDir('./dist/electron/static'),
|
||||
ignore: ['.*']
|
||||
},
|
||||
{
|
||||
from: resolveAppDir(appConfig.electron.paths.main),
|
||||
to: resolveAppDir('./dist/electron/main.js')
|
||||
}
|
||||
]) : null,
|
||||
// isProduction ? new BabiliWebpackPlugin() : null,
|
||||
// isProduction ? new webpack.LoaderOptionsPlugin({ minimize: true }) : null,
|
||||
],
|
||||
optimization: {
|
||||
noEmitOnErrors: false
|
||||
},
|
||||
devServer: {
|
||||
// contentBase: './dist', // dist path is directly configured in express
|
||||
hot: true,
|
||||
quiet: true
|
||||
},
|
||||
node: {
|
||||
// prevent webpack from injecting useless setImmediate polyfill because Vue
|
||||
// source contains it (although only uses it if it's native).
|
||||
setImmediate: false,
|
||||
// process is injected via DefinePlugin, although some 3rd party
|
||||
// libraries may require a mock to work properly (#934)
|
||||
process: 'mock',
|
||||
// prevent webpack from injecting mocks to Node native modules
|
||||
// that does not make sense for the client
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty'
|
||||
}
|
||||
}
|
||||
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// config.devtool = ''
|
||||
|
||||
// config.plugins.push(
|
||||
// new BabiliWebpackPlugin(),
|
||||
// new CopyWebpackPlugin([
|
||||
// {
|
||||
// from: path.join(__dirname, '../static'),
|
||||
// to: path.join(__dirname, '../dist/electron/static'),
|
||||
// ignore: ['.*']
|
||||
// }
|
||||
// ]),
|
||||
// new webpack.DefinePlugin({
|
||||
// 'process.env.NODE_ENV': '"production"'
|
||||
// }),
|
||||
// new webpack.LoaderOptionsPlugin({
|
||||
// minimize: true
|
||||
// })
|
||||
// )
|
||||
// }
|
||||
|
||||
return config;
|
||||
return config;
|
||||
}
|
||||
|
||||
module.exports = getConfig;
|
||||
|
Loading…
Reference in New Issue
Block a user