Last active
December 10, 2016 07:13
-
-
Save quangv/97088a598403cace05eee1e5b5dc7113 to your computer and use it in GitHub Desktop.
Monaca Vue.js Webpack config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["es2015"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"framework_version": "3.5", | |
"cordova_version": "6.2", | |
"plugins": [ | |
"mobi.monaca.plugins.Monaca" | |
], | |
"external_plugins": [ | |
"cordova-plugin-whitelist@1.2.2", | |
"cordova-plugin-splashscreen@3.2.2", | |
"cordova-custom-config@2.0.3" | |
], | |
"template-type": "react", | |
"build": { | |
"transpile": { | |
"enabled": true | |
} | |
}, | |
"xcode_version": "7" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my-project", | |
"version": "0.0.1", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"preview": "monaca preview --no-open", | |
"upload": "monaca upload" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "" | |
}, | |
"author": "Quang Van <quang@absentsoft.com>", | |
"license": "UNLICENSED", | |
"bugs": { | |
"url": "" | |
}, | |
"homepage": "", | |
"private": true, | |
"devDependencies": { | |
"babel-preset-es2015": "^6.18.0", | |
"nw": "^0.18.6", | |
"vue-loader": "^10.0.1", | |
"vue-template-compiler": "^2.1.3" | |
}, | |
"dependencies": { | |
"vue": "^2.1.3" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
var path = require('path'); | |
var os = require('os'); | |
var cordovaNodeModules = path.join(os.homedir(), '.cordova', 'node_modules'); | |
var webpack = require(path.join(cordovaNodeModules, 'webpack')); | |
var HtmlWebpackPlugin = require(path.join(cordovaNodeModules, 'html-webpack-plugin')); | |
var ExtractTextPlugin = require(path.join(cordovaNodeModules, 'extract-text-webpack-plugin')); | |
var ProgressBarPlugin = require(path.join(cordovaNodeModules, 'progress-bar-webpack-plugin')); | |
var autoprefixer = require(path.join(cordovaNodeModules, 'autoprefixer')); | |
var precss = require(path.join(cordovaNodeModules, 'precss')); | |
} catch (e) { | |
throw new Error('Missing Webpack Build Dependencies.'); | |
} | |
module.exports = { | |
devtool: 'eval-source-map', | |
context: __dirname, | |
debug: true, | |
cache: true, | |
entry: [ | |
'webpack-dev-server/client?http://0.0.0.0:8000/', | |
'webpack/hot/only-dev-server', | |
'./src/main' | |
], | |
output: { | |
path: path.join(__dirname, 'www'), | |
filename: 'bundle.js', | |
publicPath: '/' | |
}, | |
resolve: { | |
root: [ | |
path.join(__dirname, 'src'), | |
path.join(__dirname, 'node_modules') | |
], | |
extensions: ['', '.js', '.vue', '.json', '.css', '.html', '.styl'], | |
unsafeCache: true, | |
alias: { | |
webpack: path.join(cordovaNodeModules, 'webpack'), | |
'webpack-dev-server/client': path.join(cordovaNodeModules, 'webpack-dev-server', 'client') | |
} | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.vue$/, | |
loader: 'vue-loader', | |
options: { | |
// vue-loader options go here | |
loaders: { | |
js: 'babel' | |
} | |
} | |
}, | |
{ | |
test: /\.js$/, | |
loader: 'babel', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.html$/, | |
loader: 'html' | |
}, { | |
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/, | |
loader: 'file?name=assets/[name].[hash].[ext]' | |
}, { | |
test: /\.styl$/, | |
loader: 'style!css!postcss!stylus' | |
}, { | |
test: /\.css$/, | |
exclude: path.join(__dirname, 'src'), | |
loader: ExtractTextPlugin.extract('style', 'css?sourceMap') | |
}, { | |
test: /\.css$/, | |
include: path.join(__dirname, 'src'), | |
loader: 'raw' | |
}, { | |
test: /\.json$/, | |
loader: 'json' | |
}] | |
}, | |
vue: { | |
loaders: { | |
js: 'babel' | |
} | |
}, | |
babel: { | |
presets: [ | |
path.join(cordovaNodeModules, 'babel-preset-es2015') | |
], | |
}, | |
postcss: function() { | |
return [precss, autoprefixer]; | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin(), | |
new ExtractTextPlugin('[name].css'), | |
new HtmlWebpackPlugin({ | |
template: 'src/public/index.html.ejs', | |
chunksSortMode: 'dependency' | |
}), | |
new ProgressBarPlugin() | |
], | |
resolveLoader: { | |
root: cordovaNodeModules | |
}, | |
devServer: { | |
contentBase: './src/public', | |
colors: true, | |
inline: false, | |
historyApiFallback: true, | |
host: '0.0.0.0', | |
stats: 'minimal', | |
hot: true | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
var path = require('path'); | |
var os = require('os'); | |
var cordovaNodeModules = path.join(os.homedir(), '.cordova', 'node_modules'); | |
var webpack = require(path.join(cordovaNodeModules, 'webpack')); | |
var HtmlWebpackPlugin = require(path.join(cordovaNodeModules, 'html-webpack-plugin')); | |
var ExtractTextPlugin = require(path.join(cordovaNodeModules, 'extract-text-webpack-plugin')); | |
var CopyWebpackPlugin = require(path.join(cordovaNodeModules, 'copy-webpack-plugin')); | |
var ProgressBarPlugin = require(path.join(cordovaNodeModules, 'progress-bar-webpack-plugin')); | |
var autoprefixer = require(path.join(cordovaNodeModules, 'autoprefixer')); | |
var precss = require(path.join(cordovaNodeModules, 'precss')); | |
} catch (e) { | |
throw new Error('Missing Webpack Build Dependencies. '); | |
} | |
var useCache = !!process.env.WP_CACHE; | |
module.exports = { | |
context: __dirname, | |
cache: useCache, | |
stats: { | |
warnings: false, | |
children: false | |
}, | |
entry: { | |
app: './src/main', | |
vendor: ['vue'] | |
}, | |
output: { | |
path: path.join(__dirname, 'www'), | |
filename: '[name].bundle.js', | |
chunkFilename: '[name].chunk.js' | |
}, | |
resolve: { | |
root: [ | |
path.join(__dirname, 'src'), | |
path.join(__dirname, 'node_modules') | |
], | |
extensions: ['', '.js', '.vue', '.json', '.css', '.html', '.styl'], | |
unsafeCache: useCache, | |
alias: { | |
webpack: path.join(cordovaNodeModules, 'webpack') | |
} | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.vue$/, | |
loader: 'vue-loader', | |
options: { | |
// vue-loader options go here | |
loaders: { | |
js: 'babel' | |
} | |
} | |
}, | |
{ | |
test: /\.js$/, | |
loader: 'babel', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.html$/, | |
loader: 'html' | |
}, | |
{ | |
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/, | |
loader: 'file?name=assets/[name].[hash].[ext]' | |
}, { | |
test: /\.styl$/, | |
loader: 'style!css!postcss!stylus' | |
}, { | |
test: /\.css$/, | |
exclude: path.join(__dirname, 'src'), | |
loader: ExtractTextPlugin.extract('style', 'css?sourceMap') | |
}, { | |
test: /\.css$/, | |
include: path.join(__dirname, 'src'), | |
loader: 'raw' | |
}, { | |
test: /\.json$/, | |
loader: 'json' | |
}] | |
}, | |
vue: { | |
loaders: { | |
js: 'babel' | |
} | |
}, | |
postcss: function() { | |
return [precss, autoprefixer]; | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify('production') | |
} | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: ['vendor'] | |
}), | |
new ExtractTextPlugin('[name].css'), | |
new HtmlWebpackPlugin({ | |
template: 'src/public/index.html.ejs', | |
chunksSortMode: 'dependency', | |
externalCSS: ['components/loader.css'], | |
externalJS: ['components/loader.js'], | |
minify: { | |
caseSensitive: true, | |
collapseWhitespace: true, | |
conservativeCollapse: true, | |
removeAttributeQuotes: true, | |
removeComments: true | |
} | |
}), | |
new webpack.NoErrorsPlugin(), | |
new webpack.optimize.DedupePlugin(), | |
new webpack.optimize.UglifyJsPlugin(), | |
new CopyWebpackPlugin([{ | |
from: path.join(__dirname, 'src', 'public'), | |
ignore: ['index.html.ejs'] | |
}]), | |
new ProgressBarPlugin() | |
], | |
resolveLoader: { | |
root: cordovaNodeModules | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment