Last active
December 7, 2022 11:29
-
-
Save isuke/59271edb2e66af90da52582b0809d05e to your computer and use it in GitHub Desktop.
webpack.config sampla
This file contains hidden or 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
const path = require('path'); | |
const webpack = require('webpack'); | |
const merge = require('webpack-merge'); | |
const AssetsPlugin = require('assets-webpack-plugin'); | |
const baseConfig = require('./webpack.config.base.js'); | |
var config = merge(baseConfig, { | |
entry: { | |
'build-admin': './app/frontend/javascripts/application-admin.js', | |
}, | |
output: { | |
path: path.resolve(__dirname, '..', 'public', 'webpack', 'admin'), | |
}, | |
plugins: [ | |
new AssetsPlugin() | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.scss$/, | |
use: [ | |
{ loader: 'style-loader' , options: { sourceMap: true } }, | |
{ loader: 'css-loader' , options: { sourceMap: true } }, | |
{ loader: 'postcss-loader', options: { sourceMap: true } }, | |
{ loader: 'sass-loader' , options: { sourceMap: true } } | |
] | |
}, | |
{ | |
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
use: "url-loader?limit=10000&mimetype=application/font-woff" | |
}, | |
{ | |
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
use: "file-loader" | |
}, | |
{ | |
test: /\.vue$/, | |
use: { | |
loader: 'vue-loader', | |
options: { | |
loaders: { | |
js: ['babel-loader'], | |
coffee: [ | |
'babel-loader', | |
{ | |
loader: 'coffee-loader', | |
options: { | |
failOnWarns: false, | |
failOnErrors: true | |
} | |
}, | |
'coffeelint-loader' | |
], | |
scss: [ | |
{ loader: 'vue-style-loader', options: { sourceMap: true }}, | |
{ loader: 'css-loader' , options: { sourceMap: true }}, | |
{ loader: 'postcss-loader' , options: { sourceMap: true }}, | |
{ loader: 'sass-loader' , options: { sourceMap: true }}, | |
{ | |
loader: 'sass-resources-loader', | |
options: { | |
resources: [ | |
path.resolve(__dirname, '..', 'app/frontend/stylesheets/admin/_variables.scss'), | |
path.resolve(__dirname, '..', 'app/frontend/stylesheets/admin/_mixins.scss') | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
] | |
} | |
}); | |
if (process.env.NODE_ENV === "production") { | |
config = merge(config, { | |
output: { | |
filename: '[name]-[hash].js', | |
publicPath: '/webpack/admin/' | |
}, | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin({ | |
output: { | |
comments: require('uglify-save-license') | |
} | |
}), | |
], | |
devtool: '#source-map' | |
}); | |
} else { | |
config = merge(config, { | |
output: { | |
filename: '[name].js', | |
publicPath: 'http://localhost:3001/webpack/admin/' | |
}, | |
devtool: '#eval-source-map', | |
devServer: { | |
contentBase: 'public/webpack/admin/', | |
compress: true, | |
port: '3001', | |
headers: { | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS", | |
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization" | |
} | |
}, | |
}); | |
} | |
module.exports = config; |
This file contains hidden or 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
const path = require('path'); | |
const webpack = require('webpack'); | |
const WebpackRailsI18nJS = require('webpack-rails-i18n-js-plugin'); | |
module.exports = { | |
cache: true, | |
stats: { | |
warningsFilter: /Module not found: Error: Can't resolve 'react'/, | |
}, | |
resolve: { | |
extensions: ['.js', '.coffee', '.scss', '.vue'], | |
alias: { | |
'@root': path.resolve(__dirname, '..', 'app', 'frontend'), | |
'@javascripts': path.resolve(__dirname, '..', 'app', 'frontend', 'javascripts'), | |
'@stylesheets': path.resolve(__dirname, '..', 'app', 'frontend', 'stylesheets') | |
} | |
}, | |
plugins: [ | |
new webpack.ProvidePlugin({ | |
'_': 'lodash', | |
'i18n': 'i18n', | |
'axios': 'axios', | |
'qs': 'qs', | |
'toastr': 'toastr' | |
}), | |
new WebpackRailsI18nJS({ | |
locale: 'ja', | |
defaultLocale: 'ja', | |
localesPath: path.resolve(__dirname, '..', 'config', 'locales') | |
}), | |
new webpack.DefinePlugin({ | |
'process.env': { | |
NODE_ENV: JSON.stringify(process.env.NODE_ENV) | |
} | |
}) | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
enforce: 'pre', | |
use: 'eslint-loader' | |
}, | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: 'babel-loader' | |
}, | |
{ | |
test: /\.coffee$/, | |
exclude: /node_modules/, | |
enforce: 'pre', | |
use: [ | |
{ | |
loader: 'coffeelint-loader', | |
options: { | |
failOnWarns: false, | |
failOnErrors: true | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.coffee$/, | |
exclude: /node_modules/, | |
use: ['babel-loader', 'coffee-loader'] | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment